C Program to Find Grade of a Student Using If Else

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

C Program to Find Grade of a Student Using If Else statement | The if-else statement in C is a selection statement. When dealing with selection statements, there are generally three versions: one-way, two-way, and multi-way. One way decision statements do a particular thing or they do not. Two-way decision statements can do one thing or do another. Multi-way decision statements can do one of many different things depending on the value of an expression.

Prerequisites for finding grade of a student using if-else statements:-

The below table shows the grading system.

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

Program description:- Write a C Program to Find Grade of a Student Using If Else statement.

#include<stdio.h>
int main()
{
   // variables
   int score;
   char grade;

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

   // check score is valid or not
   // score is valid if it belongs to 0-100
   if(score<0 || score>100) {
     printf("Invalid Score");
     // stop execution
     return 0;
   }

   // find grade for given score
   // for score >= 90
   if(score>=90 && score<=100)
     grade = 'A';

   // for score>=80 and <90
   else if(score>=80)
     grade = 'B';

   // for score>=70 and <80
   else if(score>=70)
     grade = 'C';

   // for score>=60 and <70
   else if(score>=60)
     grade = 'D';

   // for score>=50 and <60
   else if(score>=50)
     grade = 'E';

   // for score<50
   else
     grade = 'F';

   // display grade
   printf("Grade: %c\n", grade);

   return 0;
}

Output:-

Enter score(0-100): 79
Grade: C

Enter score(0-100): 64
Grade: D

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

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

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

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

Enter score(0-100): 105
Invalid Score

Enter score(0-100): -15
Invalid Score

In this program, we have declared score and grade variables. The score variables will be used to store input from the end-user and the grade variable will store the grade value after finding the grade using an if-else statement. Then we have taken the input value from the end-user and stored it in the score variable.

Now, checked the entered score is valid or not. If the score doesn’t belong to 0 to 100 (inclusive) then it will be treated as invalid score. In that it will display the appropriate message and stop the execution of the program.

If the score is valid then we will start finding the grade based on the given score. From the table, if the score is greater than or equal to 90 then the grade will ‘A’, and so on. For a score lesser than 50 the grade will be ‘F’. Finally, we displayed the grade value on the screen.

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

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

Leave a Reply