fork download
  1. #include <stdio.h>
  2. #define STUDENTS 3
  3. #define EXAMS 4
  4.  
  5. // 7.24
  6. void printArray(int grades[][EXAMS], int students, int exams);
  7. void minimum(int grades[][EXAMS], int students, int exams);
  8. void maximum(int grades[][EXAMS], int students, int exams);
  9. void average(int grades[][EXAMS], int students, int exams);
  10.  
  11.  
  12. int main(void)
  13. {
  14. int studentGrade[STUDENTS][EXAMS] =
  15. {{77, 68, 86, 98},
  16. {75, 78, 96, 68},
  17. {84, 89, 77, 80}};
  18.  
  19. void (*processGrade[4])(int[][EXAMS], int, int) = { printArray, minimum, maximum, average };
  20.  
  21. printf("%s", " 0 Print the array of grades \n1 Find the minimum grade\n2 Find the maximum grade\n3 Print the average on all tests for each student\n4 End program\n");
  22. int choise;
  23. scanf("%d", &choise);
  24. while (choise >= 0 && choise < 4)
  25. {
  26. (*processGrade[choise])(studentGrade, STUDENTS, EXAMS);
  27.  
  28. printf("%s", " 0 Print the array of grades \n1 Find the minimum grade\n2 Find the maximum grade\n3 Print the average on all tests for each student\n4 End program\n");
  29. scanf("%d", &choise);
  30. }
  31. printArray(studentGrade, STUDENTS, EXAMS);
  32. minimum(studentGrade, STUDENTS, EXAMS);
  33. maximum(studentGrade, STUDENTS, EXAMS);
  34. average(studentGrade, STUDENTS, EXAMS);
  35.  
  36. }
  37. void printArray(int grades[][EXAMS], int students, int exams)
  38. {
  39. printf("%s", " [0] [1] [2] [3]");
  40. for (int i = 0; i < students; i++)
  41. {
  42. printf("\nStudentGrade[%d] ", i);
  43.  
  44. for (int j = 0; j < exams; j++)
  45. {
  46. printf("%-5d", grades[i][j]);
  47.  
  48. }
  49. }
  50. }
  51.  
  52. void minimum(int grades[][EXAMS], int students, int exams)
  53. {
  54. int min = grades[0][0];
  55.  
  56. for (int i = 0; i < students; i++)
  57. {
  58. for (int j = 0; j < exams; j++)
  59. {
  60. if (grades[i][j] < min)
  61. {
  62. min = grades[i][j];
  63. }
  64. }
  65. }
  66. printf("\nLOwer grade: %d\n", min);
  67. }
  68.  
  69. void maximum(int grades[][EXAMS], int students, int exams)
  70. {
  71. int max = grades[0][0];
  72.  
  73. for (int i = 0; i < students; i++)
  74. {
  75. for (int j = 0; j < exams; j++)
  76. {
  77. if (grades[i][j] > max)
  78. {
  79. max = grades[i][j];
  80. }
  81. }
  82. }
  83. printf("Highest grade: %d\n", max);
  84. }
  85.  
  86. void average(int grades[][EXAMS], int students, int exams)
  87. {
  88. int sum = 0;
  89. double aver;
  90.  
  91. for (int i = 0; i < students; i++)
  92. {
  93. for (int j = 0; j < exams; j++)
  94. {
  95. sum += grades[i][j];
  96. }
  97.  
  98. aver = sum / 4.0;
  99. printf("the average grade for student %d is %f\n", (i+1), aver);
  100. }
  101.  
  102.  
  103. }
Success #stdin #stdout 0.01s 5324KB
stdin
0
1
2
3
4
stdout
 0  Print the array of grades 
1  Find the minimum grade
2  Find the maximum grade
3  Print the average on all tests for each student
4  End program
                [0]  [1]  [2]  [3]
StudentGrade[0] 77   68   86   98   
StudentGrade[1] 75   78   96   68   
StudentGrade[2] 84   89   77   80    0  Print the array of grades 
1  Find the minimum grade
2  Find the maximum grade
3  Print the average on all tests for each student
4  End program

LOwer grade: 68
 0  Print the array of grades 
1  Find the minimum grade
2  Find the maximum grade
3  Print the average on all tests for each student
4  End program
Highest grade: 98
 0  Print the array of grades 
1  Find the minimum grade
2  Find the maximum grade
3  Print the average on all tests for each student
4  End program
the average grade for student 1 is 82.250000
the average grade for student 2 is 161.500000
the average grade for student 3 is 244.000000
 0  Print the array of grades 
1  Find the minimum grade
2  Find the maximum grade
3  Print the average on all tests for each student
4  End program
                [0]  [1]  [2]  [3]
StudentGrade[0] 77   68   86   98   
StudentGrade[1] 75   78   96   68   
StudentGrade[2] 84   89   77   80   
LOwer grade: 68
Highest grade: 98
the average grade for student 1 is 82.250000
the average grade for student 2 is 161.500000
the average grade for student 3 is 244.000000