C program to check character is vowel or not
- Five letter 'A' 'E' 'I' 'O' 'U' are called vowels. All other alphabets excepts these vowels are called consonants.
#include
int main()
{
char c; // character value
int lowercase, uppercase; // integer value
printf("Enter an alphabet: "); // user enter character
scanf("%c", &c); // storing value
// evaluates to 1 if variable c is lowercase
lowercase = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
// evaluates to 1 if variable c is uppercase
uppercase = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
// evaluates to 1 if c is either lowercase or uppercase
if (lowercase || uppercase)
printf("%c is a vowel.", c);
else
printf("%c is a consonant.", c);
return 0;
}
Output
Enter an alphabet : G
G is consonant.
- The character entered by the user is stored in c.
- The lowercase variable evaluated to 1 (true) if c is a lowercase vowel and 0 (false) for any other character.
- Similarly, the uppercase variable evaluated to 1 (true) if c is an uppercase vowel and 0 (false) for any other character.
- if either lowercase or uppercase variable is 1( ture), the entered character is vowel.
- However, if both lowercase and uppercase variables are 0, the entered character is consonant.
Happy Coding
0 comments:
Post a Comment