Write a C program to enter the marks of a student in four subjects. Then calculate the total, aggregate and display the grades obtained by the student (Using SWITCH).
#include < stdio.h>
int main()
{
int phy, chem, math, comp, sum, agg;
float per;
/* Input marks of four subjects from user */
printf("Enter four subjects marks: ");
scanf("%d%d%d%d", &phy, &chem, &math, &comp);
/* Calculate percentage */
sum = phy + chem + math + comp;
per =sum / 4.0;
//agg = sum / 4;
agg = per;
// auto conversion from float to int
printf("Percentage = %.2f\n", per);
printf("aggregate = %d\n", agg);
switch(agg/10)
{
case 10:
case 9: printf("Grade A \n");
break;
case 8: printf("Grade B \n");
break;
case 7: printf("Grade C \n");
break;
case 6: printf("Grade D \n");
break;
case 5: printf("Grade Pass \n");
break;
default: printf("Fail \n");
}
return 0;
}