Vowel or consonant checking

Vowel or consonant : In English, there are 5 vowel letters i. e. ‘a’,  ‘e’,  ‘i’,  ‘o’,  ‘u’. Other letters are consonant. In this C++ programming guide we will see C++ programs to check whether a character is vowel or consonant.

You can also check the same program whether a character is vowel or consonant using C language. However, we can use if else statement as well as switch statement for this purpose. Let’s see the program bellow;

Program to check vowel or consonant

Here we will check for both the uppercase letter or lowercase letter. We have used Boolean variable to check the given letter. You can use only if else statement without using Boolean variables. Then you have to write the whole condition inside the if condition. See the program bellow.

// consonant or vowel program in C++

#include<iostream>
using namespace std;

int main(){
    char a;
    bool is_upper_vowel, is_lower_vowel;

    cout <<"Enter the alphabet to check : ";
    cin >>a;

    is_lower_vowel = (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u');

    is_upper_vowel = (a == 'A' || a == 'E' || a == 'I' || a == 'O' || a == 'U');

    if ( !isalpha(a) ){
      printf("\nYou should enter and alphabet to check.\n");

    }else if(is_lower_vowel || is_upper_vowel){
        cout <<"\nVowel.\n";

    }else{
        cout <<"\nConsonant.\n";
    }

    return 0;
}

Output of vowel or consonant program:

vowel-or-consonant-program-in-c-check-vowel-or-consonant-by-c
vowel-or-consonant-program-checking-vowel-or-consonant

You can write the same program using switch statement. The logic will be same but you have to implement switch statement to write the program. Try this.

Previous pageEven or odd

Next pageFind largest number