# C program to calculate Percentage and Grade

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.

## C program to calculate percentage of 5 subjects

``````#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;
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");
}
return 0;
}``````

## output

```enter marks obtain in five subject:50
40
60
70
90
average is 62.000000
• Take input of 5 subject marks from user and store in `phy`, `chem`, `eng`, `math`, and `comp`.
• Calculate the total mark obtain in all five subjects and store it in the sum variable i.e `sum=phy+chem+eng+math+comp.`
• Divide the sum of all subjects by the total number of subjects to find the average i.e. `avg = total / 5`.
• For calculating percentages use the formula which is, `percentage=(sum/500)*100`.