Q:

C program to read the grade of student print equivalent description

0

C program to read the grade of student print equivalent description

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Read the grade of the student from the user, and print an equivalent message.

Program:

The source code to read a grade of student print equivalent description is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

// C program to read a grade of student and
// print equivalent description

#include <stdio.h>

int main()
{
    char grade = 0;

    printf("Enter Grade: ");
    scanf("%c", &grade);

    switch (grade) {
    case 'a':
    case 'A':
        printf("Excellent");
        break;

    case 'b':
    case 'B':
        printf("Very Good");
        break;

    case 'c':
    case 'C':
        printf("Good");
        break;

    case 'y':
    case 'Y':
        printf("You are absent");
        break;

    case 'f':
    case 'F':
        printf("You are failed");
        break;

    default:
        printf("Invalid grade");
        break;
    }

    return 0;
}

Output:

Enter Grade: A
Excellent

Explanation:

Here, we created a variable grade of character type, and read the value of the grade variable and print the appropriate message on the screen.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C programming Basic Input, Output, if else, Ternary Operator based Programs

Similar questions


need a help?


find thousands of online teachers now
<< C program to read the height of a person and the p...