Q:

C program to read gender (M/F) and print corresponding gender using switch

0

C program to read gender (M/F) and print corresponding gender using switch

This program will read one character gender (M,m,F,f) and print the full gender (Female, Male or unspecified) using switch case statement in c programming language.

All Answers

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

Print gender (Male/Female) program according to given M/F using switch

/*C program to read gender (M/F) and print corresponding gender using switch.*/
 
#include <stdio.h>
 
int main()
{
    char gender;
     
    printf("Enter gender (M/m or F/f): ");
    scanf("%c",&gender);
     
    switch(gender)
    {
        case 'M':
        case 'm':
            printf("Male.");
            break;
        case 'F':
        case 'f':
            printf("Female.");
            break;
        default:
            printf("Unspecified Gender.");
    }
    printf("\n");
    return 0;
}

Output

    First Run:
    Enter gender (M/m or F/f): M
    Male.

    Second Run:
    Enter gender (M/m or F/f): x
    Unspecified Gender.

 

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

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now