Bugkexercise 5.5 calculating average student grades.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.