Q. Accept a character from the user and check whether the character is a an vowel or consonant. (Hint: a,e,i,o,u are vowels)
Program
#include <stdio.h>
int main()
{
char c;
int isLowercaseVowel, isUppercaseVowel;
printf("Enter a alphabet: ");
scanf("%c",&c);
isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
if (isLowercaseVowel || isUppercaseVowel)
printf("%c is a vowel.", c);
else
printf("%c is a consonant.", c);
}
Output:
Enter a alphabet: t
t is a consonant.
Program
#include <stdio.h>
int main()
{
char c;
int isLowercaseVowel, isUppercaseVowel;
printf("Enter a alphabet: ");
scanf("%c",&c);
isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
if (isLowercaseVowel || isUppercaseVowel)
printf("%c is a vowel.", c);
else
printf("%c is a consonant.", c);
}
Output:
Enter a alphabet: t
t is a consonant.
0 Comments