C Program to find grade of a student

May 2, 2022, Learn eTutorial

For a better understanding, we always recommend you to learn the basic topics of C programming listed below:

How to check a student's grade in C?

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.

What is strcpy() function?

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.

The main logic of the program is first to declare the character Array remark[] and the variable Grade. Accept the Grade from the user and save it into the variable Grade. Convert the Grade into uppercase by calling the function toupper(). Then by using a Switch statement, check the Grade is 'S' or 'A' or 'B' or 'Y' or 'F.' If the Grade is 'S', then set the variable remark to SUPER by using the function strcpy(). If the Grade is A, then set the comment as VERY GOOD. If the Grade is 'F', then set the remark as FAIR. If the Grade is 'Y' then set the comment as ABSENT. If the Grade is 'F', then set the remark as FAILS. By default, set the statement as an error in grade. Then display the result as a remark using the print function.


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.

C Source Code

                                          #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");
  case 'A':
    strcpy(remark, " VERY GOOD"); /* switch statement passes the control to proper statement. */
  case 'B':
    strcpy(remark, " FAIR");
  case 'Y':
    strcpy(remark, " ABSENT");
  case 'F':
    strcpy(remark, " FAILS");
    strcpy(remark, "ERROR IN GRADE\n");
  } /* End of switch */
  printf("RESULT  : %s\n", remark);
} /* End of main() */



Enter the grade


Enter the grade