Codeforcoding

C program to check Vowel or consonant using switch case

C program to check Vowel or consonant using switch case

In this article, we will discuss the concept of the C program to Check Vowel or consonant using switch case statements

In this post, we are going to learn how to check the vowels and consonants using switch statements in C  programming language

 

C program to check Vowel or consonant using switch case
Check vowel and consonants

C program to check Vowel or consonant using switch case with the break

The program allows to enter an Alphabet and it checks and displays whether the given alphabet is vowel or consonant with the break statements

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char ch;
    printf("Enter any Alphabet\n"); //input alphabet from user
    scanf("%c",&ch);//store the Entered Alphabet in ch

    switch(ch){
    //check lower case vowel letters
    case 'a':
    printf("%c is a vowel",ch);
    break;

    case 'e':
    printf("%c is a vowel",ch);
    break;

    case 'i':
    printf("%c is a vowel",ch);
    break;

    case 'o':
    printf("%c is a vowel",ch);
    break;

    case 'u':
    printf("%c is a vowel",ch);
    break;

    //check upper case vowel letters
    case 'A':
    printf("%c is a vowel",ch);
    break;

    case 'E':
    printf("%c is a vowel",ch);
    break;

    case 'I':
    printf("%c is a vowel",ch);
    break;

    case 'O':
    printf("%c is a vowel",ch);
    break;

    case 'U':
    printf("%c is a vowel",ch);
    break;

    default:
    printf("%c is a consonant",ch);
    break;
    }
    getch();

    return 0;
    }

When the above code is executed, it produces the following result

case 1

Enter any Alphabet
a
a is a vowel

 

case 2

Enter any Alphabet
E
E is a vowel

 

case 3

Enter any Alphabet
M
M is a consonant


case 4

Enter any Alphabet
y
y is a consonant

Approach

 

C program to check Vowel or consonant using switch case without the break

The program allows to enter an Alphabet and it checks and displays whether the given alphabet vowel or consonant without the break statements

Program 2

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char ch;
    printf("Enter any Alpabet\n"); //input alphabet from user
    scanf("%c",&ch);//store the Entered Alphabet in ch

    switch(ch){
    //check lower case vowel letters
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':

    //check upper case vowel letters
    case 'A':
    case 'E':
    case 'I':
    case 'O':
    case 'U':

        printf("%c is a vowel",ch);
        break;

    default:
        printf("%c is a consonant",ch);
        break;

}
    getch();

    return 0;
    }

 

When the above code is executed, it produces the following result

case 1

Enter any Alphabet
e
e is a vowel

 

case 2

Enter any Alphabet
U
U is a vowel

 

case 3

Enter any Alphabet
G
G is a consonant


case 4

Enter any Alphabet
r
r is a consonant

 

Approach

 

 

Suggested for you

Data type in C language

Variable in C language

The operator in C language

Switch case statements in C language

 

Similar post

Java program to check Vowel or consonant using switch case statements

C++ program to Check Vowel or consonant using switch case statements

C++ program to Check Vowel or consonant using switch case
C++ Program for count upper or lowercase letter of the given string
Exit mobile version