ADVERTISEMENT
ADVERTISEMENT

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 »



ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.