Program to check alphabet is vowel or consonant in cpp

 

 In c++ language program to check alphabet is vowel or consonant:

 

 

In this article, you’ll learn to check whether an alphabet entered by the user is consonant or vowel in C++ program with example and explain in detail.

As we know that: A, E, I, O, U or a, e, i, o, u is a vowel except this all are consonant in the alphabet A to Z.

Step by step explanation:

  • First, we create three variables, they are lowercase, uppercase, and alpha
  • Print “ Enter an alphabet “ on the screen
  • User give an input which is alphabet then
  • We Store input alphabet which is entered by the user in the alpha variable with the help of predefined function scanf then
  • We check input alphabet is vowel or not
  • If vowel then print on screen alphabet is a vowel
  • Otherwise, print on the screen alphabet is consonant

 

Q: write a program in c++ language to check whether an alphabet is vowel or consonant input is given by user from the keyboard.

Solution:

#include<iostream>

#include<conio.h>

using namespace std;

int main()

{

 

int lowerCase, upperCase;

char alpha;

cout<<“Enter an alphabet: “;

cin>>alpha;

upperCase=(alpha==’A’ || alpha==’E’ || alpha==’I’ || alpha==’O’ || alpha==’U’);

lowerCase=(alpha==’a’ || alpha==’e’ || alpha==’i’ || alpha==’o’ || alpha==’u’);

if(upperCase || lowerCase)

cout<<alpha<<” is a vowel”;

else

cout<<alpha<<” is a consonant”;

return 0;

 

}

 

The output of this program:

Enter an alphabet: f

f is a consonant

Note: if the user enters any number except vowel then print on screen “  is a consonant” because this programming only checking alphabet is vowel or consonant.

Q: write a program in c++ language to check whether an alphabet is a vowel or consonant using do-while, the input is given by user from the keyboard.

Solution:

#include<iostream>

#include<conio.h>

using namespace std;

int main()

{

 

int lowerCase, upperCase;

char alpha;

do{

cout<<“Enter an alphabet: “;

cin>>alpha;

}

while (!(alpha));

upperCase=(alpha==’A’ || alpha==’E’ || alpha==’I’ || alpha==’O’ || alpha==’U’);

lowerCase=(alpha==’a’ || alpha==’e’ || alpha==’i’ || alpha==’o’ || alpha==’u’);

if(upperCase || lowerCase)

cout<<alpha<<” is a vowel”;

else

cout<<alpha<<” is a consonant”;

return 0;

 

}

 

The output of this program:

Enter an alphabet: e

e is a vowel

Leave a Reply

Your email address will not be published. Required fields are marked *

itetrade.com