Coding Practice

Write a C program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer

Input marks of five subjects and calculate the grade

Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following:

    Percentage >= 80% : Grade A+
    Percentage >= 75% : Grade A
    Percentage >= 70% : Grade A-
    Percentage >= 65% : Grade B+
    Percentage >= 60% : Grade B
    Percentage >= 55% : Grade B-
    Percentage >= 50% : Grade C+
    Percentage >= 45% : Grade C
    Percentage >= 40% : Grade D
    Percentage < 40% : Grade F

Sample Output
Physics: 83

Chemistry: 89

Biology: 71

Mathematics: 85

Computer: 82

Grade A+

Process returned 0 (0x0)   execution time : 15.385 s
Press any key to continue.
Source Code
#include<stdio.h>
 
int main()
{
    int phy, che, bio, mat, c, marks;
 
    printf("Physics: ");
    scanf("%d", &phy);
 
    printf("\nChemistry: ");
    scanf("%d", &che);
 
    printf("\nBiology: ");
    scanf("%d", &bio);
 
    printf("\nMathematics: ");
    scanf("%d", &mat);
 
    printf("\nComputer: ");
    scanf("%d", &c);
 
    marks = (phy + che + bio + mat + c) / 5;
 
    if(marks >= 80 && marks <= 100)
    {
        printf("\nGrade A+\n");
    }
    else if(marks >= 75 && marks <= 79)
    {
        printf("\nGrade A\n");
    }
    else if(marks >= 70 && marks <= 74)
    {
        printf("\nGrade A-\n");
    }
    else if(marks >= 65 && marks <= 69)
    {
        printf("\nGrade B+\n");
    }
    else if(marks >= 60 && marks <= 64)
    {
        printf("\nGrade B\n");
    }
    else if(marks >= 55 && marks <= 59)
    {
        printf("\nGrade B-\n");
    }
    else if(marks >= 50 && marks <= 54)
    {
        printf("\nGrade C+\n");
    }
    else if(marks >= 45 && marks <= 49)
    {
        printf("\nGrade C\n");
    }
    else if(marks >= 40 && marks <= 44)
    {
        printf("\nGrade D\n");
    }
    else if(marks < 40)
    {
        printf("\nFail!\n");
    }
    else
    {
        printf("\nInvalid marks!\n");
    }
 
    return 0;
}
Sample Output
Physics: 78

Chemistry: 67

Biology: 80

Mathematics: 75

Computer: 77

Grade A

Process returned 0 (0x0)   execution time : 12.276 s
Press any key to continue.
Change Theme
X