Q21. Write a code to check whether a character is vowel or consonant
Vowel :- In English, five alphabets A, E, I, O, and U are called as Vowels.
Consonant :- In English, all alphabets other than vowels are Consonant.
For Example :-
Input = E
Output = E is Vowel.
So as we can see that E is alphabets which is Vowel. So, the output is “E is Vowel”.
check whether a character is vowel or consonant Algorithm
START
Step 1 – Input the alphabets.
Step 2 – Check if the alphabets is (a, e, i, o, u) if alphabet is among these then it is vowel.
Step 3 – If the alphabets is vowel than print Vowel otherwise print Consonant.
STOP
check whether a character is vowel or consonant code
#include <stdio.h>
int main() {
char c=’M’;
int lc, uc;
// evaluates to 1 if variable c is lowercase
lc = (c == ‘a’ || c == ‘e’ || c == ‘i’ || c == ‘o’ || c == ‘u’);
// evaluates to 1 if variable c is uppercase
uc = (c == ‘A’ || c == ‘E’ || c == ‘I’ || c == ‘O’ || c == ‘U’);
// evaluates to 1 if c is either lowercase or uppercase
if (lc || uc)
printf(“%c is a vowel.”, c);
else
printf(“%c is a consonant.”, c);
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
char c=’M’;
int lc, uc;
// evaluates to 1 (true) if c is a lowercase vowel
lc = (c == ‘a’ || c == ‘e’ || c == ‘i’ || c == ‘o’ || c == ‘u’);
// evaluates to 1 (true) if c is an uppercase vowel
uc = (c == ‘A’ || c == ‘E’ || c == ‘I’ || c == ‘O’ || c == ‘U’);
// evaluates to 1 (true) if either lc or uc is true
if (lc || uc)
cout << c << ” is a vowel.”;
else
cout << c << ” is a consonant.”;
return 0;
}
public class LFC
{
public static void main(String args[])
{
char ch=’M’;
if(ch==’a’ || ch==’A’ || ch==’e’ || ch==’E’ ||
ch==’i’ || ch==’I’ || ch==’o’ || ch==’O’ ||
ch==’u’ || ch==’U’)
{
System.out.printf(“%c is a Vowel”,ch);
}
else
{
System.out.printf(“%c is a Consonant”,ch);
}
}
}
# Python Program to check character is Vowel or Consonant
ch = ‘M’
if(ch == ‘a’ or ch == ‘e’ or ch == ‘i’ or ch == ‘o’ or ch == ‘u’ or ch == ‘A’
or ch == ‘E’ or ch == ‘I’ or ch == ‘O’ or ch == ‘U’):
print(ch, “is a Vowel”)
else:
print(ch, “is a Consonant”)
function check_vowel($ch)
{
if ($ch == ‘a’ || $ch == ‘e’ ||
$ch == ‘i’ || $ch == ‘o’ ||
$ch == ‘u’)
echo “$ch is aVowel” ;
else
echo “$ch is a Consonant”;
}
// Driver code
check_vowel(‘M’);
Output
M is a consonant.
Recommended Programs
Program to find factorial of a number
Program to count number of digits in a number