Write a C program that will accept five subjects from the user; calculate sum of the 5 subjects, calculate percentage and grade according to following conditions:
Percentage >= 90% : Grade A
Percentage >= 80% : Grade B
Percentage >= 70% : Grade C
Percentage >= 60% : Grade D
Percentage >= 40% : Grade E
Percentage < 40% : Grade F
Code:
#include<stdio.h>
int main() {
int s1, s2, s3, s4, s5, sum, total = 500;
float per;
printf("\nEnter grades of the 5 subjects: ");
scanf("%d %d %d %d %d", &s1, &s2, &s3, &s4, &s5);
sum = s1 + s2 + s3 + s4 + s5;
per = (sum * 100) / total;
printf("Percentage: %.2f\n", per);
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);
}