Q:

C program to check whether a character is VOWEL or CONSONANT using switch

0

C program to check whether a character is VOWEL or CONSONANT using switch

This program will read a character from user and check whether it is VOWEL or CONSONANT if entered character was an alphabet 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

Check VOWEL or CONSONANT program using switch

/*C program to check whether a character is VOWEL or CONSONANT using switch.*/
 
#include <stdio.h>
 
int main()
{
    char ch;
     
    printf("Enter a character: ");
    scanf("%c",&ch);
     
    //condition to check character is alphabet or not
    if((ch>='A' && ch<='Z') || (ch>='a' && ch<='z'))
    {
        //check for VOWEL or CONSONANT
        switch(ch)
        {
            case 'A':
            case 'E':
            case 'I':
            case 'O':
            case 'U':
            case 'a':
            case 'e':
            case 'i':
            case 'o':
            case 'u':
                printf("%c is a VOWEL.\n",ch);
                break;
            default:
                printf("%c is a CONSONANT.\n",ch);            
        }
    }
    else
    {
        printf("%c is not an alphabet.\n",ch);
    }
 
    return 0;
}

Output

    First Run:
    Enter a character: E  
    E is a VOWEL.  
 
    Second Run:
    Enter a character: X
    X is a CONSONANT.

    Third Run:
    Enter a character: +
    + is not an alphabet.

 

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

total answers (1)

C program to design calculator with basic operatio... >>
<< C program to read gender (M/F) and print correspon...