22. Write a C program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following:
Percentage >= 90% : Grade A
Percentage >= 80% : Grade B
Percentage >= 70% : Grade C
Percentage >= 60% : Grade D
Percentage >= 40% : Grade E
Percentage < 40% : Grade F
Solution :-
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
float phy,che,bio,maths,comp,total,avg;
printf("Enter the marks of Physics :-");
scanf("%f",&phy);
printf("Enter the marks of Chemistry :-");
scanf("%f",&che);
printf("Enter the marks of Biology:-");
scanf("%f",&bio);
printf("Enter the marks of Mathematics:-");
scanf("%f",&maths);
printf("Enter the marks of Comuter:-");
scanf("%f",&comp);
total = phy+che+bio+maths+comp;
avg = total/5;
printf("\nThe Total marks you Scored :- %f",total);
printf("\nThe Percentage you get :-%f",avg);
if(avg >=90)
{
printf("\nYour Grade is A");
}
else if(avg >=80)
{
printf("\nYour Grade is B");
}
else if (avg >=70)
{
printf("\nYour Grade is C");
}
else if(avg >=60)
{
printf("\nYour Grade is D");
}
else if(avg >=40)
{
printf("\nYour Grade is E");
}
else if (avg <40)
{
printf("\nYour Grade is F");
}
else
{
printf("\nYour are Fail");
}
getch();
}
Output :-