Task: Read a single character and classify it as vowel, consonant, digit, or other. Use a switch with grouped cases for vowels.
/* Program: Character Classifier using switch (U2) What it does: - Reads a single character. - Uses switch-grouped cases for vowels; checks for digits; else consonant/other.*/
#include <stdio.h>
#include <ctype.h>
int main(void) {
char ch;
printf("Enter a character: ");
if (scanf(" %c", &ch) != 1) {
printf("Invalid input.
");
return 0;
} ch = tolower((unsigned char)ch);
switch (ch) {
case 'a': case 'e': case 'i': case 'o': case 'u':
printf("vowel
"); break;
default:
if (ch >= '0' && ch <= '9') {
printf("digit
");
} else if (ch >= 'a' && ch <= 'z') {
printf("consonant
");
} else {
printf("other
");
} }return 0;
}