Question
4) Write a C program that calculates the average scores of a class of total 9 students. The scores of the students are: 82, 65,
4) Write a C program that calculates the average scores of a class of total 9 students. The scores of the students are: 82, 65, 98, 57, 90, 80, 86, 79 and 92. Also computes the statistics on number of A, B, C, D and F students, use the range given in syllabus.
So far this is what I have:
/* Write a C program that calculates the average scores of a class of total 9 students. The scores of the students are: 82, 65, 98, 57, 90, 80, 86, 79 and 92. Also computes the statistics on number of A, B, C, D and F students. */
# include
int main(void) { unsigned int counter; //number of grades entered int grade; //grade score int total; //sum of grades
float average; //number with decimal point for avg
//initilization phase total = 0; //total counter = 0; //loop counter
//processing phase //get first grade printf("%s", "Enter grade, -1 to end: "); //prompt input scanf("%d", &grade); //read grade
//loop while sentinel value not yet entered while (grade != -1) { total = total + grade; //add grade to total counter = counter + 1; //increment counter
//get next grade printf("%s", "Enter grade, -1 to end: "); //prompt input scanf("%d", &grade); //read next grade } //termination phase //if at least one grade is entered if (counter != 0) { //calculate avg of all grades average = (float)total/counter;
//display avg with two digits of precision printf("Class average is %.2f ", average); } //otherwise if no grades are entered else { puts("No grades were entered."); } } //end program
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started