Write a C program to take marks of 5 subjects from user and calculate its percentage and display the grade.
Source code:
#include
int main()
{
int sub1,sub2,sub3,sub4,sub5;
printf("Enter sub1 marks:");
scanf("%d",&sub1);
printf("Enter sub2 marks:");
scanf("%d",&sub2);
printf("Enter sub3 marks:");
scanf("%d",&sub3);
printf("Enter sub4 marks:");
scanf("%d",&sub4);
printf("Enter sub5 marks:");
scanf("%d",&sub5);
float t_marks=(sub1+sub2+sub3
+sub4+sub5)/5;
float perct=t_marks*100;
if(perct > 75)
{
printf("Grade: A");
}
else if(perct > 60 && perct <= 75)
{
printf("Grade: B");
}
else if(perct >= 50 && perct < 60)
{
printf("Grade: C");
}
else
{
printf("Fail");
}
return 0;
}
Output:
Enter sub1 marks:100
Enter sub2 marks:100
Enter sub3 marks:100
Enter sub4 marks:100
Enter sub5 marks:100
Grade: A
Comments
Post a Comment