This C program reads a grade and displays its equivalent description.
This program takes a grade as input and displays its equivalent description.
1. Take the grade as input.
2. Use switch statement to verify the grade.
3. Print the output and exit.
Here is source code of the C program to read a grade & display the equivalent description. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C Program to accept a grade and declare the equivalent description
* if code is S, then print SUPER
* if code is A, then print VERY GOOD
* if code is B, then print FAIR
* if code is Y, then print ABSENT
* if code is F, then print FAILS
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
void main()
{
char remark[15];
char grade;
printf("Enter the grade \n");
scanf("%c", &grade);
/* lower case letter to upper case */
grade = toupper(grade);
switch(grade)
{
case 'S':
strcpy(remark, " SUPER");
break;
case 'A':
strcpy(remark, " VERY GOOD");
break;
case 'B':
strcpy(remark, " FAIR");
break;
case 'Y':
strcpy(remark, " ABSENT");
break;
case 'F':
strcpy(remark, " FAILS");
break;
default :
strcpy(remark, "ERROR IN GRADE \n");
break;
}
printf("RESULT : %s\n", remark);
}
1. Take the letter as input and store it in the variable grade.
2. Convert the input letter into its uppercase using function toupper().
3. Using switch statement, verify the input letter.
4. If the letter is S, then copy the string ” SUPER” into the variable remark and break.
5. If the letter is A, then copy the string ” VERY GOOD” into the variable remark and break.
6. If the letter is B, then copy the string ” FAIR” into the variable remark and break.
7. If the letter is Y, then copy the string ” ABSENT” into the variable remark and break.
8. If the letter is F , then copy the string ” FAILS” into the variable remark and break.
9. In the default case, copy the string ” ERROR IN GRADE” into the variable remark and break.
10. Print the variable remark as output and exit.
Enter the grade s RESULT : SUPER Enter the grade a RESULT : VERY GOOD Enter the grade b RESULT : FAIR Enter the grade y RESULT : ABSENT Enter the grade f RESULT : FAILS
Sanfoundry Global Education & Learning Series – 1000 C Programs.
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
- Watch Advanced C Programming Videos
- Practice Computer Science MCQs
- Apply for Computer Science Internship
- Check C Books
- Check Computer Science Books