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.

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.

C Switch Case Programs »


Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.