For a better understanding, we always recommend you to learn the basic topics of C programming listed below:
Here in this C program, we need to make the Students Grade with the description, which means we have to show the description when the user enters the Grade. So in this C program, first, we use the toupper function to change the Grade into Uppercase. Now we use a Switch statement to pass the control to the respective description. If the user enters s, then the toupper() function changes the s to uppercase S, and then the Switch statement passes the control to the case S.
Then the proper Output will be displayed and control Exit from the switch statement. In this program, we use a Break statement. The break statement is a jump instruction mainly used in for loop, while loop, and do-while loop. Here we use the strcpy function to copy the remarks.
It is a standard library function and which we use to copy one string to another. In the C program, it is present in the 'string.h' header file. The syntax of the strcpy() function is.
char* strcpy(char* dest,const char* src);
The strcpy() function replaces the source string with the destination string.
STEP 1: Include the Header files to use the built-in functions in the C program.
STEP 2: Include the Header file string.h.
STEP 3: Declare the array remark[25] as a Character type and declare the variable Grade as a character.
STEP 4: Read the Grade from the user and save it into the variable Grade.
STEP 5: Covert the Grade into uppercase using the function toupper(Grade).
STEP 6: Using the Switch
statement check, the Grade is S or A or B or Y or F.
STEP 7: If the Grade is A, then set the remark as VERY GOOD using the strcpy() function.
STEP 8: If the Grade is B, then set the remark as FAIR using strcpy() function.
STEP 9: If the Grade is Y, then set the remark as ABSENT using strcpy() function.
STEP 10: If the Grade is F, then set the remark as FAILS using strcpy() function.
STEP 11: By Default case, set remark as ERROR IN GRADE using strcpy() function.
STEP 12: Then display the RESULT as a remark.
#include <stdio.h>
#include <ctype.h>
#include <string.h>
void main() {
char remark[15];
char grade;
printf("Enter the grade\n");
scanf("%c", & grade);
grade = toupper(grade); /* lower case letter to upper case */
switch (grade) {
case 'S':
strcpy(remark, " SUPER");
break;
case 'A':
strcpy(remark, " VERY GOOD"); /* switch statement passes the control to proper statement. */
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;
} /* End of switch */
printf("RESULT : %s\n", remark);
} /* End of main() */
RUN 1 Enter the grade s RESULT: SUPER RUN 2 Enter the grade y RESULT: ABSENT