Write a Program to find the given character is a vowel or not .
C++ programming || Computer Science
Share
Write a Program to find the given character is a vowel or not .
C++ programming || Computer Science
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
using namespace std;
int main()
{
char vow;
cout << "Enter a character:";
cin >> vow;
switch(vow)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
cout << "The entered character is a vowel";
break;
default:
cout<<"The entered character is a consonant";
break;
}
return 0;
}
Output:
(1)
Enter a character: o
The Entered character is a vowel.
(2)
Enter a character: b
The Entered character is a consonant.
Hope this helps!
Answer:
The question can be solved by 2 methods...
Method-1 (Using if)
#include<constream.h>
void main()
{
clrscr();
char ch;
cout<<"\n Enter any character: ";
cin>>ch;
if(ch=='a'¦¦ch=='A')
cout<<"\n Character is a vowel";
if(ch=='e'¦¦ch=='E')
cout<<"\n Character is a vowel";
if(ch=='i'¦¦ch=='I')
cout<<"\n Character is a vowel";
if(ch=='o'¦¦ch=='O')
cout<<"\n Character is a vowel";
if(ch=='u'¦¦ch=='U')
cout<<"\n Character is a vowel";
else
cout<<"\n character is not a vowel";
getch();
}
Method-2 (using switch)
#include<constream.h>
void main()
{
clrscr();
char ch;
cout<<"\n Enter any character";
cin>>ch;
switch(ch)
{
case 'a':cout<<"Vowel";
case 'A':cout<<"Vowel";
case 'e':cout<<"Vowel";
case 'E':cout<<"Vowel";
case 'i':cout<<"Vowel";
case 'I':cout<<"Vowel";
case 'o':cout<<"Vowel";
case 'O':cout<<"Vowel";
case 'u':cout<<"Vowel";
case 'U':cout<<"Vowel";
default:cout<<"Constant";
}
getch();
}