Judging from the output, the program is wrong. I don't know what it means at all.
Exercise 5-5. Write a program that would calculate the average grade for the students in
Each of the arbitrary number of classes. The program should read in all the grades for
Students in all classes before calculating the averages. Output the student grades
For each of the class followed by the average for that class.
//Exercise 5.5 calculating average student grades.#include <stdio.h>#include<stdbool.h>#include<ctype.h>intMainvoid) {size_t nclasses=0;//Number Classessize_t Nstudents_max =0;//Maximum number of students in a class CharAnswer ='N'; printf ("How many students is in the largest class?:"); scanf ("%zd", &Nstudents_max); printf ("How many classes is there?:"); scanf ("%zd", &nclasses); size_tclass=0; size_t Student=0 ; intGrades[nclasses][nstudents_max];//Stores the gradessize_t students[nclasses];//Stores The number of students in each class for(class=0;class< nclasses; ++class) {printf ("Enter The grades for students in class%zd.\n",class+1); students[class] =0;//Student count within a class while(true) {printf ("Enter The integer grade for student%zd:", students[class] +1); scanf ("%d", &grades[class][students[class]]); if(++students[class] = = Nstudents_max)//Increment and check student Count{printf ("Class%zd complete.",class+1); Break; } printf ("Any further students in class%zd (Y or N):",class+1); scanf ("%c", &answer); if(ToUpper (answer) = ='N') Break; }} printf ("\ n"); for(class=0;class< nclasses; ++class) { intClass_total =0; printf ("Student Grades for class%zd are:\n",class+1); for(Student =0; Student < students[class] ; ++student) {Class_total+ = grades[class][student]; if((Student +1) %6==0) printf ("\ n"); printf ("%5d", grades[class][student]); } printf ("\naverage grade for Class%zd is%.2lf\n",class+1, (Double) class_total/students[class]); } return 0;}
Bugkexercise 5.5 calculating average student grades.