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,
Table of Contents
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 Obtained | Equivalent Grade |
---|---|
>=90 | A |
80-89 | B |
70-79 | C |
60-69 | D |
50-59 | E |
<50 | F |
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.
2nd Test Case: If the student score marks between 80 to 89 then the output will be Grade B.
3rd Test Case: If the student score marks between 70 to 79 then the output will be Grade C.
4th Test Case: If the student score marks between 60 to 69 then the output will be Grade D.
5th Test Case: If the student score marks between 50 to 59 then the output will be Grade E.
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 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:
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:
- C Program to Make Simple Calculator
- Armstrong Number Program in C
- Fibonacci Series Program in C
- Decimal to Binary Conversion Program in C
- Reverse a String in C
- Program to Reverse a Number in C
- Hello World Program in C
- Palindrome Program in C
- Leap Year Program in C
- Factorial Program in C
- Prime Number Program in C
- Program to print prime numbers from 1 to n
- Anagram program in C.
- Calculate LCM Program in C.
- Addition of Two Numbers in C
- Matrix Multiplication Program in C.
- Playfair Cipher Program in C.
- GCD Program in C.
- Tower of Hanoi in C.
- First Fit Program in C
- Swapping of two numbers in C
- Menu Driven Program in C.
- Odd or Even number program in C
- Round Robin Program in C
- Quadratic Equation Program in C.