C Program to Find Grade of Student Using Switch Statement

Flow Control
If-else Statement in C
Programs on if-else
Switch Case in C
Switch case Programs
Conditional Operator
While loop in C
Do-while loop in C
While vs do-while
For loop in C
Break keyword in C
Continue keyword in C
Break vs Exit in C
Goto keyword in C
☕️ Flow Control Programs
Largest in 3 Numbers
Find Grade of student
Find the absolute value
Vowel or Consonant
Leap Year Program
Simple calculator in C
Check Odd or Even 
Roots of Quadratic Equation
Find Reverse of Number
Factors of a number in C
Generate Multiplication table
Find Power of a Number
Find GCD and LCM
Find factorial of Number
Count Number of Digits
Sum of digits in Number
Sum of N Natural Numbers
Sum of Squares of Natural No.
Find Sum of Odd Numbers
Find the Sum of Series
Find Fibonacci series in C
Sum of the Fibonacci series
Sum until enters +ve numbers
Sum of max 10 no. & Skip -ve
☕️ C Conversion Programs
Celsius to Fahrenheit
Fahrenheit to Celsius
Decimal ↔ Binary
Decimal ↔ Octal
Octal ↔ Binary in C
☕️ Number Programs in C
Prime Number in C
Strong Number in C
Krishnamurthy Number
Neon Number in C
Palindrome number
Perfect Number in C
Armstrong Number
☕️ Pattern Programs in C
Pattern programs in C
Printing pattern using loops
Floyd’s triangle Program
Pascal Triangle Program
Pyramid Star Pattern in C
Diamond Pattern Programs
Half Diamond pattern in C
Print Diamond Pattern
Hollow Diamond Pattern
Diamond Pattern of Numbers

Here, we will write a C program to find the grade of a student using switch case statements. The below table shows the grading system.

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

Prerequisites for finding grade of a student using switch case statements:-

C program to find grade of a student using switch case statement

#include<stdio.h>
int main()
{
   int score;

   printf("Enter score( 0-100 ): ");
   scanf("%d", &score);

   switch( score / 10 )
   {

   case 10:
   case 9:
     printf("Grade: A");
     break;

   case 8:
     printf("Grade: B");
     break;

   case 7:
     printf("Grade: C");
     break;

   case 6:
     printf("Grade: D");
     break;

   case 5:
     printf("Grade: E");
     break;

   default:
     printf("Grade: F");
     break;

   }

   return 0;
}

Output for the test-case-1:-

Enter score( 0-100 ): 100
Grade: A

Output for the test-case-2:-

Enter score( 0-100 ): 95
Grade: A

Output for the test-case-3:-

Enter score( 0-100 ): 80
Grade: B

Enter score( 0-100 ): 50
Grade: E

Output for the test-case-5:-

Enter score( 0-100 ): 49
Grade: F

Enter score( 0-100 ): 30
Grade: F

The condition of the switch case is score/10, so, the score every is divided by 10 and the matched label will be executed. For score 90-100 is A, so for labels 9 and 10, the grade will be A. Similarly, for other ranges. If the score is below 50 then score/10 gives below 5 and it doesn’t match with any condition hence, the default statement will be executed.

Using nested if-else statement

The same program also can be written using nested if-else statements. Here in every condition, the score will be compared.

#include<stdio.h>
int main()
{
   int score;

   printf("Enter score( 0-100 ): ");
   scanf("%d",&score);

   if(score>=90 && score<=100)
     printf("Grade: A");

   else if(score>=80)
     printf("Grade: B");

   else if(score>=70)
     printf("Grade: C");

   else if(score>=60)
     printf("Grade: D");

   else if(score>=50)
     printf("Grade: E");

   else
     printf("Grade: F");

   return 0;
}

If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!

Similar C programming examples on if-else and switch-case statements

Flow Control
If-else Statement in C
Programs on if-else
Switch Case in C
Switch case Programs
Conditional Operator
While loop in C
Do-while loop in C
While vs do-while
For loop in C
Break keyword in C
Continue keyword in C
Break vs Exit in C
Goto keyword in C
☕️ Flow Control Programs
Largest among 3 Numbers
Find Grade of student
Find the absolute value
Check Vowel or Consonant
Leap Year Program
Simple calculator in C
Check Odd or Even 
Roots of Quadratic Equation
Find Reverse of Number
Factors of a number in C
Generate Multiplication table
Find Power of a Number
Find GCD and LCM
Find factorial of Number
Count Number of Digits
Sum of digits in Number
Sum of N Natural Numbers
Sum of Squares of Natural No.
Find Sum of Odd Numbers
Find the Sum of Series
Find Fibonacci series in C
Sum of the Fibonacci series
Sum until enters +ve numbers
Sum of max 10 no. & Skip -ve
☕️ C Conversion Programs
Celsius to Fahrenheit
Fahrenheit to Celsius
Decimal ↔ Binary
Decimal ↔ Octal
Octal ↔ Binary in C
☕️ Number Programs in C
Prime Number in C
Strong Number in C
Krishnamurthy Number
Neon Number in C
Palindrome number
Perfect Number in C
Armstrong Number
☕️ Pattern Programs in C
Pattern programs in C
Printing pattern using loops
Floyd’s triangle Program
Pascal Triangle Program
Pyramid Star Pattern in C
Diamond Pattern Programs
Half Diamond pattern in C
Print Diamond Pattern
Hollow Diamond Pattern
Diamond Pattern of Numbers

5 thoughts on “C Program to Find Grade of Student Using Switch Statement”

  1. Switch case…When I input 101-109, it becomes A. Likewise, when I input negative numbers, it becomes F instead of the default Error message. This is my grading scale:
    A = 90 -100, B = 80-89, C = 70 -79, D = 60 – 69, and F = 0 -59.

    Please do help I’m a beginner. Appreciate it!

    1. In that case, you need to handle the case when the input value is greater than 100 and less than 0. If the input value is greater than 100 or negative then we should display “invalid input”. See the below program:-

      #include<stdio.h>
      int main()
      {
         int score;
      
         printf("Enter score( 0-100 ): ");
         scanf("%d", &score);
      
         if(score == 100) {
             score -= 1;
         }
      
         switch( score / 10 )
         {
      
         case 9:
           printf("Grade: A");
           break;
      
         case 8:
           printf("Grade: B");
           break;
      
         case 7:
           printf("Grade: C");
           break;
      
         case 6:
           printf("Grade: D");
           break;
      
         case 5:
           printf("Grade: E");
           break;
      
         case 4:
         case 3:
         case 2:
         case 1:
         case 0:
           printf("Grade: F");
           break;
      
         default:
           printf("Invalid input");
           break;
      
         }
      
         return 0;
      }
      
  2. Please can there be multiple switches in the C program? I have been trying to add another switch operation, but the program keeps returning to zero after the first switch statement is executed.

Leave a Comment

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