#include <stdio.h>
#define STUDENTS 3
#define EXAMS 4
void minimum(const int grades[][EXAMS], size_t pupils, size_t tests,int low[]);
void maximum(const int grades[][EXAMS], size_t pupils, size_t tests,int max[]);
double average(const int setOfGrades[][EXAMS], size_t tests, size_t exam);
void printArray(const int grades[][EXAMS], size_t pupils, size_t tests);
int main(void)
{
int lowGrade[STUDENTS]={100,100,100},maxGrade[STUDENTS]={0};
double averageGrade[EXAMS]={0};
int studentGrades[STUDENTS][EXAMS] =
{ { 77, 68, 86, 73 },
{ 96, 87, 89, 78 },
{ 70, 90, 86, 81 } };
puts("The array is:");
printArray(studentGrades, STUDENTS, EXAMS);
minimum(studentGrades, STUDENTS, EXAMS,lowGrade);
maximum(studentGrades, STUDENTS, EXAMS,maxGrade);
puts("");
for(int i=0;i<STUDENTS;i++){
printf("The max and min grades of student %d are %d and %d\n",
i,maxGrade[i],lowGrade[i]);
}
for (size_t exam = 0; exam < EXAMS; ++exam) {
printf("The average grade for exam %u is %.2f\n",
exam, average(studentGrades, STUDENTS,exam));
}
}
void minimum(const int grades[][EXAMS], size_t pupils, size_t tests,int low[])
{
for(size_t i=0;i<pupils;++i)
for(size_t j=0;j<tests;++j){
if(low[i]>grades[i][j])
low[i]=grades[i][j];
}
return;
}
void maximum(const int grades[][EXAMS], size_t pupils, size_t tests,int max[])
{
for (size_t i = 0; i < pupils; ++i) {
for (size_t j = 0; j < tests; ++j) {
if (grades[i][j] > max[i]) {
max[i] = grades[i][j];
}
}
}
return;
}
double average(const int setOfGrades[][EXAMS], size_t tests, size_t exam)
{
int total = 0;
for (size_t i = 0; i < tests; ++i) {
total += setOfGrades[i][exam];
}
return (double) total / tests;
}
void printArray(const int grades[][EXAMS], size_t pupils, size_t tests)
{
printf("%s", " [0] [1] [2] [3]");
for (size_t i = 0; i < pupils; ++i) {
printf("\nstudentGrades[%u] ", i);
for (size_t j = 0; j < tests; ++j) {
printf("%-5d", grades[i][j]);
}
}
}