TechyQuest.xyz - Learn With Coding Examples

Learn programming with the examples of programs. Techyquest provides lot of programming examples to learn programming and logic.

Recents in Beach

LightBlog
Responsive Ads Here

Popular Posts

Sunday, 26 January 2020

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;
}

No comments:

Post a comment