- We first declare a character variable
c
to store the user input. - We prompt the user to enter a character using
printf
and accept the input using scanf
. - We check if the entered character is a vowel or a consonant using the
if
condition. If the character matches any of the vowel characters (lowercase or uppercase), we print a message saying that the character is a vowel. Otherwise, we print a message saying that it is a consonant. - Finally, we return 0 to indicate successful execution of the program.
- this program assumes that the user enters a single character only. If you need to accept a string as input and check each character individually, you will need to modify the program accordingly.
#include <stdio.h>
int main() {
char c;
printf("Enter a character: ");
scanf("%c", &c);
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') {
printf("%c is a vowel.\n", c);
} else {
printf("%c is a consonant.\n", c);
}
return 0;
}
OUTPUT
Enter a character: t
t is a consonant.