C Program to Check Whether Character Is Vowel Or Consonant


C program to check whether a character is vowel or consonant using if else statement

#include <stdio.h>

int main()
{
    char ch; //It will store the choice of user
    printf("Enter the character\n");
    scanf("%c",&ch);
    
    //Converting lowercase to uppercase
    if(ch>='a' && ch<='z')
        ch -= 32; // ch = ch-32;
    
    if(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')
        printf("Character is vowel");
    else
        printf("Charcter is consonant");
    
    return 0;
}


C program to check whether a character is vowel or consonant using switch case

#include <stdio.h>

int main()
{
    char ch; //It will store the choice of user
    printf("Enter the character\n");
    scanf("%c",&ch);
    
    //Converting lowercase to uppercase
    if(ch>='a' && ch<='z')
        ch -= 32; // ch = ch-32;
    
    switch(ch){
        case 'A':
        case 'E':
        case 'I':
        case 'O':
        case 'U':
            printf("Character is vowel");
            break;
        default:
            printf("Character is consonant");
    }
    
    return 0;
}

Post a comment

Post a Comment (0)

Previous Post Next Post