In: Computer Science
Write a C program that prints the Grade of each student in a class based on their mark. The program must also print the average mark of the class.
The program must prompt (ask) the user for the mark of a student (out of 100).
The program must then print the mark entered and the grade received based on the table below.
Grade |
Range |
A |
85 to 100 inclusive |
B |
75 to 85 inclusive |
C |
60 to 70 inclusive |
D |
50 to 60 inclusive |
F |
Less than 50 |
For example “The student mark is 87 and their grade is A.”
This must be done repeatedly until a mark of -1 is entered.
The average mark of all of the class must then be shown.
For Example “The average mark of the class is 34.23.”
Note: To calculate the average, you must add up (total) all of the marks and then divide by the number of students (number of marks entered)
Complete C Program with output is given below.
C Code :
#include <stdio.h>
int main()
{
int marks[100],i=0,sum=0,k=0;
float avg;
while(k==0)
{
printf("Enter mark (out of 100) : ");
scanf("%d",&marks[i]);
if(marks[i]==-1)
{
k++;
break;
}
if(marks[i]>85 && marks[i]<=100)
{
printf("The student mark is %d and his grade is
A.\n",marks[i]);
}
else if(marks[i]>75 && marks[i]<=85)
{
printf("The student mark is %d and his grade is
B.\n",marks[i]);
}
else if(marks[i]>60 && marks[i]<=75)
{
printf("The student mark is %d and his grade is
C.\n",marks[i]);
}
else if(marks[i]>=50 && marks[i]<=60)
{
printf("The student mark is %d and his grade is
D.\n",marks[i]);
}
else if(marks[i]<50)
{
printf("The student mark is %d and his grade is
F.\n",marks[i]);
}
else
printf("Error!! Mark is not in range from 0 - 100.\n");
sum=sum+marks[i];
i++;
}
avg=(float)sum/i;
printf("The average mark of the class is %.2f.",avg);
return 0;
}
Output :
If you have any doubt regarding the solution then let me know in comment. If it helps, kindly give an upVote to this answer.