In this program, You will take five subject marks from the user, then calculate an average of five subject marks and print grades according to their five subject average marks and printing their percentage.
#include <stdio.h>
int main()
{
int phy,chem,eng,math,comp;
float sum,avg,percentage;
printf("\n enter marks obtain in five subject:");
scanf("%d%d%d%d%d",&phy,&chem,&eng,&math,&comp);
sum=(phy+chem+eng+math+comp);
avg=sum/5;
printf("\naverage is %f",avg);
percentage=(sum/500)*100;
printf("\n your grade is");
if(avg>=90)
{
printf(" A");
}
else if(avg>=75)
{
printf(" B");
}
else if(avg>=60)
{
printf(" C");
}
else if(avg>=40)
{
printf(" D");
}
else
{
printf(" fail");
}
printf("\n your percentage is %f",percentage);
return 0;
}
enter marks obtain in five subject:50 40 60 70 90 average is 62.000000 your grade is C your percentage is 62.000000
This algorithm will find the percentage and grade of students in five subjects.
phy
, chem
, eng
, math
, and comp
.sum=phy+chem+eng+math+comp.
avg = total / 5
.percentage=(sum/500)*100
.