In: Computer Science
C Programming
use notes
Start by asking the user how many grades are to be entered. Then ask for each one of theses grades. Calculate the average grade and the number of failing grades (grade less than 70). Display on the screen the average grade and the number of failing grades
C code:
#include <stdio.h>
int main()
{
//initializing total Number of grades and number
of failing grades as 0
int num,fail=0;
//initializing grade and average
float grade,average=0;
//asking for number of grades
printf("How many grades are to be entered:
");
//accpeting it
scanf("%d",&num);
//loop to accept all grades
for(int i=0;i<num;i++){
//asking for grade
printf("Enter the grade:
");
//accepting it
scanf("%f",&grade);
//adding it to
average
average+=grade;
//checking for failing
grade
if(grade<70)
//incrementing count of
fail
fail++;
}
//printing Average grade
printf("Average grade =
%.2f\n",average/(float)num);
//printing Number if failing grades
printf("Number of failing grades =
%d",fail);
return 0;
}
Screenshot:
Input and Output: