C Program To Find Grade of a Student

In this post, we will learn how to find the grade of a student using C Programming language.

C Program To Find Grade of a Student

In the program, we will take the marks of different subjects as input from the user. Then, we calculate the percentage according to the marks. 

Finally, we will display the result in terms of Grade.

So, without further ado, let’s begin this tutorial.

C Program To Find Grade of a Student

// C Program To Find Grade of a Student
#include <stdio.h>
int main(){
    int maths, english, computer, physics, chemistry;
    float total_marks, percentage;
    
    // Asking for Input
    printf("Enter the marks of Maths: ");
    scanf("%d", &maths);
    printf("Enter the marks of English: ");
    scanf("%d", &english);
    printf("Enter the marks of Computer: ");
    scanf("%d", &computer);
    printf("Enter the marks of Physics: ");
    scanf("%d", &physics);
    printf("Enter the marks of Chemistry: ");
    scanf("%d", &chemistry);
    
    total_marks = maths + english + computer + physics + chemistry;
    percentage = (total_marks / 500) * 100;
    
    if (percentage >= 91){
        printf("The Student Gets 'A' Grade");
    }
    else if (percentage >= 81){
        printf("The Student Gets 'B' Grade");
    }
    else if (percentage >= 71){
        printf("The Student Gets 'C' Grade");
    }
    else if (percentage >= 61){
        printf("The Student Gets 'D' Grade");
    }
    else if (percentage >= 51){
        printf("The Students Gets 'E' Grade");
    }
    else{
        printf("The Student Gets F Grade and result is Fail,");
    }
    return 0;
}

Output

Enter the marks of Maths: 75
Enter the marks of English: 90
Enter the marks of Computer: 95
Enter the marks of Physics: 85
Enter the marks of Chemistry: 83
The Student Gets 'B' Grade

How Does This Program Work ?

    int maths, english, computer, physics, chemistry;
    float total_marks, percentage;

In this program, we have declared five int data type variables according to the subjects. We have also declared two float data type variables which will store total marks and percentage of the student.

    // Asking for Input
    printf("Enter the marks of Maths: ");
    scanf("%d", &maths);
    printf("Enter the marks of English: ");
    scanf("%d", &english);
    printf("Enter the marks of Computer: ");
    scanf("%d", &computer);
    printf("Enter the marks of Physics: ");
    scanf("%d", &physics);
    printf("Enter the marks of Chemistry: ");
    scanf("%d", &chemistry);

Then, the user is asked to enter the marks of different subjects.

    total_marks = maths + english + computer + physics + chemistry;
    percentage = (total_marks / 500) * 100;

We calculate the percentage using the formula:

(Marks Obtained / Total Marks ) * 100.

    if (percentage >= 91){
        printf("The Student Gets 'A' Grade");
    }
    else if (percentage >= 81){
        printf("The Student Gets 'B' Grade");
    }
    else if (percentage >= 71){
        printf("The Student Gets 'C' Grade");
    }
    else if (percentage >= 61){
        printf("The Student Gets 'D' Grade");
    }
    else if (percentage >= 51){
        printf("The Students Gets 'E' Grade");
    }
    else{
        printf("The Student Gets F Grade and result is Fail,");
    }

We have used percentage parameter to calculate the grade of the student.

Conclusion

I hope after going through this post, you understand how to find the grade of a student using C Programming language.

If you have any doubt regarding the program, feel free to contact us in the comment section. We will be delighted to help you.

Also Read:

Leave a Comment

Your email address will not be published. Required fields are marked *