Program to enter a grade & check its corresponding remarks
This program accepts a grade as input (like A, B, C, etc.) and displays the corresponding remark using conditional statements. This is a good practice for learning if-else
or switch-case
in C.
#include <stdio.h> int main() { char grade; // Input from user printf("Enter your grade (A, B, C, D, F): "); scanf(" %c", &grade); // Note the space before %c to consume newline // Convert lowercase to uppercase (optional) if (grade >= 'a' && grade <= 'z') { grade = grade - 32; } // Check remarks if (grade == 'A') { printf("Excellent!\n"); } else if (grade == 'B') { printf("Very Good\n"); } else if (grade == 'C') { printf("Good\n"); } else if (grade == 'D') { printf("Needs Improvement\n"); } else if (grade == 'F') { printf("Fail\n"); } else { printf("Invalid grade entered.\n"); } return 0; } Output Enter your grade (A, B, C, D, F): B Very Good Enter your grade (A, B, C, D, F): f Fail Enter your grade (A, B, C, D, F): E Invalid grade entered.
Explanation:
-
The program takes a grade character as input.
-
It checks the value using a series of
if-else
conditions. -
Lowercase letters are converted to uppercase.
-
Based on the grade, it prints a corresponding remark.