成绩统计小程序(结构体).c 969 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <stdio.h>
  2. int main() {
  3. int n;
  4. scanf("%d", &n);
  5. struct student {
  6. int num;
  7. char name[20];
  8. int score[3];
  9. } students[100];
  10. int i, j;
  11. for (i = 0; i < n; i++) {
  12. scanf("%d %s %d %d %d", &students[i].num, students[i].name, &students[i].score[0], &students[i].score[1], &students[i].score[2]);
  13. }
  14. int total_score[3] = {0};
  15. for (i = 0; i < n; i++) {
  16. for (j = 0; j < 3; j++) {
  17. total_score[j] += students[i].score[j];
  18. }
  19. }
  20. float avg_score[3];
  21. int max_score[3] = {0};
  22. for (j = 0; j < 3; j++) {
  23. avg_score[j] = total_score[j] / (float)n;
  24. for (i = 0; i < n; i++) {
  25. if (students[i].score[j] > max_score[j]) {
  26. max_score[j] = students[i].score[j];
  27. }
  28. }
  29. }
  30. for (j = 0; j < 3; j++) {
  31. printf("aver=%.0fmax=%d\n", avg_score[j], max_score[j]);
  32. }
  33. return 0;
  34. }