C program to enter student marks and find percentage and grade using conditional operator.
C program to enter student marks and find percentage and grade using conditional operator
#include <stdio.h>
int main()
{
int phy, chem, bio, math, comp;
float per;
printf("Enter phy subjects marks: ");
scanf("%d", &phy);
printf("Enter chem subjects marks: ");
scanf("%d", &chem);
printf("Enter bio subjects marks: ");
scanf("%d", &bio);
printf("Enter math subjects marks: ");
scanf("%d", &math);
printf("Enter comp subjects marks: ");
scanf("%d", &comp);
per = (phy + chem + bio + math + comp) / 5.0;
printf("Percentage of marks = %.2f\n", per);
(per >= 90)?
printf("Grade A"):
(per >= 80)?
printf("Grade B"):
(per >= 70)?
printf("Grade C"):
(per >= 60)?
printf("Grade D"):
(per >= 40)?
printf("Grade E"):
printf("Grade F");
return 0;
}
Output:
Enter phy subjects marks: 89
Enter chem subjects marks: 96
Enter bio subjects marks: 57
Enter math subjects marks: 48
Enter comp subjects marks: 75
Percentage of marks = 73.00
Grade C