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 # 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!