In: Computer Science
( C programming ) Write a program that will process an arbitrary number of grades each time the program is run. (Hints: sentinel-controlled iteration.) If grade >= 90, its corresponding letter grade is A. If 80 <= grade < 90, its corresponding letter grade is B. If 70 <= grade < 80, its corresponding letter grade is C. If 60 <= grade < 70, its corresponding letter grade is D. If grade < 60, its corresponding letter grade is F. (a) After get all grades, calculate average.
(b) Count the numbers of all letter grades.
(c) Display a summary of the grade results indicating the number of each letter grade and the class average.
Using the following input sequence for checking: 78 68 34 85 89 96 86 91 68 81 54
// C code
#include<stdio.h>
int main()
{
int
grade,countA=0,countB=0,countC=0,countD=0,countF=0,count=0;
float average,sum=0.0;
do
{
printf("Enter grade enter -1 to stop:");
scanf("%d",&grade);
if(grade!=-1)
{
sum=sum+grade;
count++;
if(grade>=90)
countA++;
else if(grade>=80)
countB++;
else if(grade>=70)
countC++;
else if(grade>=60)
countD++;
else
countF++;
}
}while(grade!=-1);
average=sum/count;
printf("\nGrade Results:");
printf("\nGrade A : %d\nGrade B :%d\nGrade C : %d\nGrade D :
%d\nGrade F :%d ",countA,countB,countC,countD,countF);
printf("\nclass Average : %f",average);
return 0;
}