Character Type
Completed
Read one character and print vowel, consonant, digit or other (letters can be either case).
Input
One character.
Output
One word.
Example
Input
E
Output
vowel
Editor
C
Hints
ctype.h gives isalpha, isdigit, tolower, toupper.
Solution explanation
Lower-casing first halves the number of vowel checks.
Show solution
#include <stdio.h>
#include <ctype.h>
int main() {
char c;
scanf(" %c", &c);
char low = tolower(c);
if (isalpha(c)) {
if (low == 'a' || low == 'e' || low == 'i' || low == 'o' || low == 'u') {
printf("vowel\n");
} else {
printf("consonant\n");
}
} else if (isdigit(c)) {
printf("digit\n");
} else {
printf("other\n");
}
return 0;
}