Program in C to check a given character is vowel or consonant Using switch case.
#include<stdio.h> int main() { char ch; printf("Enter a character:-"); ch=getchar(); switch(ch) { case 'a': case 'A': case 'e': case 'E': case 'i': case 'I': case 'o': case 'O': case 'u': case 'U': printf("%c is vowel.",ch); break; default : printf("%c is consonant.",ch); } return 0; }
Output:-
Second method
#include<stdio.h> #include<ctype.h> int main() { char ch; printf("Enter a character:-"); ch=getchar(); switch(toupper(ch)) { case 'A': case 'E': case 'I': case 'O': case 'U': printf("%c is vowel.",ch); break; default : printf("%c is consonant.",ch); } return 0; }
Output:-
0 Comments