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;
  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;
}

output

enter marks obtain in five subject:50
40
60
70
90
average is 62.000000
your grade is C
your percentage is 62.000000

Algorithm to calculate grade and percentage of five subject

This algorithm will find the percentage and grade of students in five subjects.

  • 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.
  • Now print the grade by using an if-else statement.
  • Print the percentage of students.