6.Write a Program in C to enter marks of five subjects. Find the Sum and the Average of them and then assign grade to the students.
Sample Solution C Code:
// C Program to Find Grade of a Student Using If else Ladder
#include < stdio.h >
int main() {
    float subject_1, subject_2, subject_3, subject_4, subject_5;
    float total, average, percentage;
    char grade;
    printf("Enter the marks of five subjects::\n");
    scanf("%f%f%f%f%f", &subject_1, &subject_2, &subject_3, &subject_4, &subject_5);
    // It will calculate the Total, Average and Percentage
    total = subject_1 + subject_2 + subject_3 + subject_4 + subject_5;
    average = total / 5.0;
    percentage = (total / 500.0) * 100;
    // It will calculate the Grade
    if (average >= 90)
        grade = 'O';
    else if (average >= 80 && average < 90)
        grade = 'E';
    else if (average >= 70 && average < 80)
        grade = 'A';
    else if (average >= 60 && average < 70)
        grade = 'B';
        else if (average >= 50 && average < 60)
        grade = 'c';
        else if (average >= 400 && average < 50)
        grade = 'd';
    else
        grade = 'F';
    // It will produce the final output
    printf("\nThe Total marks is:  \t%.2f / 500.00\n", total);
    printf("\nThe Average marks is:\t%.2f\n", average);
    printf("\nThe Percentage is:   \t%.2f%%\n", percentage);
    printf("\nThe Grade is:        \t'%c'\n", grade);
    return 0;
}
Output
Enter the marks of five subjects::
95 
85 
74 
64 
53
The Total marks is:      371.00 / 500.00
The Average marks is:    74.20 
The Percentage is:       74.20% 
The Grade is:            'A'
    More >