/* C program to enter marks of five subjects and calculate percentage and grade*/
#include <stdio.h>int main()
{
int phy, chem, bio, math, comp; //Five subjects
float per;
/* Reads marks of five subjects from user */
printf("Enter five subjects marks: ");
scanf("%d%d%d%d%d", &phy, &chem, &bio, &math, &comp);
/* Calculates percentage */
per = (phy + chem + bio + math + comp) / 5.0;
printf("Percentage = %.2f\n", per);
/* Finds grade according to the percentage */
if(per >= 90)
{
printf("Grade A");
}
else if(per >= 80)
{
printf("Grade B");
}
else if(per >= 70)
{
printf("Grade C");
}
else if(per >= 60)
{
printf("Grade D");
}
else if(per >= 40)
{
printf("Grade E");
}
else
{
printf("Grade F");
}
return 0;
}
output
Enter five subjects marks: 9595
97
98
90
Percentage = 95.00
Grade A
Comments
Post a Comment