1
0

scores_in.c 804 B

12345678910111213141516171819202122232425
  1. // scores_in.c -- uses loops for array processing
  2. #include <stdio.h>
  3. #define SIZE 10
  4. #define PAR 72
  5. int main(void)
  6. {
  7. int index, score[SIZE];
  8. int sum = 0;
  9. float average;
  10. printf("Enter %d golf scores:\n", SIZE);
  11. for (index = 0; index < SIZE; index++)
  12. scanf("%d", &score[index]); // read in the ten scores
  13. printf("The scores read in are as follows:\n");
  14. for (index = 0; index < SIZE; index++)
  15. printf("%5d", score[index]); // verify input
  16. printf("\n");
  17. for (index = 0; index < SIZE; index++)
  18. sum += score[index]; // add them up
  19. average = (float) sum / SIZE; // time-honored method
  20. printf("Sum of scores = %d, average = %.2f\n", sum, average);
  21. printf("That's a handicap of %.0f.\n", average - PAR);
  22. return 0;
  23. }