Q:-C program to check whether an alphabet is a vowel or consonant. This program takes the character value(entered by user) as input and checks whether that character is a vowel or consonant using if-else statement. Since a user is allowed to enter an alphabet in lowercase and uppercase, the program checks for both uppercase and lowercase vowels and consonants.
#include<stdio.h> #include<conio.h> void main() { char ch; clrscr(); printf("Enter a character\n"); scanf("%c", &ch); if( ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') { printf("%c is vowel\n", ch); } else { printf("%c is consonant\n", ch); } getch(); }
We ask the user to enter an alphabet and store it inside character variable ch. Using if else construct we check if the user entered alphabet is vowel or consonant. Inside if condition, we check if alphabet present in variable ch is equal to a or e or i or o or u or A or E or I or O or U. If any of these conditions are true, then it’ll return true and block inside if executes orelse else block gets executed.
In the background, c program checks the ASCII value present in variable ch with the ASCII values of a, e, i, o, u, A, E, I, O, U.