Skip to main content

Write a ‘C’ program to accept marks of 5 subjects of a student and calculate the grade using rules

Write a ‘C’ program to accept marks of 5 subjects of a student and
calculate the grade using rules:
> 90 grade = O
between 75 and 90 grade = A
between 60 and 75 grade = B
between 40 and 60 grade = C
< 40 grade = F 
#include<stdio.h>
int main()
{
    int phy, chem, bio, math, comp; 
    float per; 

    /* Input marks of five subjects from user */
    printf("Enter five subjects marks: ");
    scanf("%d%d%d%d%d", &phy, &chem, &bio, &math, &comp);


    /* Calculate percentage */
    per = (phy + chem + bio + math + comp) / 5.0;

    printf("Percentage = %.2f\n", per);


    /* Find grade according to the percentage */
    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("Fail");
    }

    return 0;
}