In this tutorial, we’ll learn the c program to find grade of a student using switch case. We’ll also learn how we can find grade of a student using nested if-else statements. But, before starting the coding part we’ll see what actually the grade is. So,

What is Grade?

The grade is called as the mark which indicates the quality of work done by any student or person. The grading system is used where we’ve to arrange the data of students in a particular order. Suppose, Teacher wants to find which student has scored the maximum marks in a class or wants to find how many students are passed and failed. In such a situation, the grading system is used.

In this tutorial, we’re using an Alphabetical grading system i.e A, B, C, D, etc. So let’s see how the c program to find grade of a student using switch case is written.

C Program to Find Grade of a Student Using Switch Case

In this program we’ll write c program using switch case by referring to the below chart:

Marks ObtainedEquivalent Grade
>=90A
80-89B
70-79C
60-69D
50-59E
<50F

From the above table, If student score marks >=90 then the grade will be given as A. Similarly, B grade for scoring marks between 80-89, Grade C for 70-79, Grade D for 60-69, Grade E for 50-59. If the student scores below 50 marks then the grade will be given as F which means fail.

//Learnprogramo - Programming made simple
#include<stdio.h>
int main()
{
   int marks;
   // accept input from the user
   printf("\nEnter the Marks Between 0 To 100:");
   scanf("%d", &marks);
   
   if(marks>100)
   {
    //If user enters marks greater than 100
    printf("\nPlease Enter marks between 0 to 100\n");
   }
   else
   {
   switch(marks/10)
   {
       case 10 :
       case 9 :
           //Marks between 90-100
           printf("\n Your Grade is: A");
           break;
       case 8 :
            // Marks between 80-89
           printf("\n Your Grade is: B" );
           break;
       case 7 :
           // Marks between 70-79
           printf("\n Your Grade is: C" );
           break;
       case 6 :
           // Marks between 60-69
           printf("\n Your Grade is: D" );
           break;
       case 5 :
            // Marks between 50-59
           printf("\n Your Grade is: E" );
           break;
       default :
           //Marks less than 50
           printf("\n You Grade is: F & you're Failed\n");
   }
 }
   return 0;
}

Outputs:

1st Test Case: If the student score marks between 90 to 100 then the output will be Grade A.

c program to find grade of a student using switch case

2nd Test Case: If the student score marks between 80 to 89 then the output will be Grade B.

c program to find grade of a student using switch case

3rd Test Case: If the student score marks between 70 to 79 then the output will be Grade C.

c program to find grade of a student using switch case

4th Test Case: If the student score marks between 60 to 69 then the output will be Grade D.

c program to find grade of a student using switch case

5th Test Case: If the student score marks between 50 to 59 then the output will be Grade E.

c program to find grade of a student using nested if else

6th Test Case: If the student score marks below 50 then the output will be Grade F and the student is failed the exam.

c program to find grade of a student using for loop

C Program to Find Grade of a Student Using Nested if else

In this program, we’ll see how we can find grade of a student using nested if else statements.

//Learnprogramo - Programming made simple
#include<stdio.h>
int main()
{
   int marks;
   printf("\nEnter the Marks Between 0 To 100:");
   scanf("%d",&marks);
   if(marks>=90 && marks<=100)
     printf("Grade is: A");
   else if(marks>=80)
     printf("Grade is: B");
   else if(marks>=70)
     printf("Grade is: C");
   else if(marks>=60)
     printf("Grade is: D");
   else if(marks>=50)
     printf("Grade is: E");
   else
     printf("Grade is: F & You're failed");
   return 0;
}

Output:

c program to find grade of a student using switch case

In the above output, I’ve entered marks as 55 so the grade I get is Grade E. So, in this way we’ve done the code for the C program to find grade of a student using if else statements.

Conclusion

In this way, we’ve learned about the c program to find grade of a student using switch case. If you have any doubts related to code then please feel free to contact us. We’ll reply as soon as possible.

Thanks & Happy Coding :)

Also Read: