Q.)WAP to check vowel or consonant using switch case in C program.
#include < stdio.h>
int main()
{
char ch;
printf("Enter any alphabet: ");
scanf("%c", &ch);
switch(ch)
{
case 'a':
printf("Vowel");
break;
case 'e':
printf("Vowel");
break;
case 'i':
printf("Vowel");
break;
case 'o':
printf("Vowel");
break;
case 'u':
printf("Vowel");
break;
case 'A':
printf("Vowel");
break;
case 'E':
printf("Vowel");
break;
case 'I':
printf("Vowel");
break;
case 'O':
printf("Vowel");
break;
case 'U':
printf("Vowel");
break;
default:
printf("Consonant");
}
getch();
}
Output
Enter any alphabet: E
VOWEL
Program Explanation
Step 1 : Include header files (#include< stdio.h> and #include< conio.h>).
Step 2 : Start with main function with return type.
Step 3 : parenthesis to start and end the program { }.
Step 4 : declare variables with data type i.e, 'ch' is an character type so we use "char" data type.
Step 5 : Use output function printf() to print the output on the screen.
Step 6 : Use input function scanf() to get input from the user.
Step 7 : here, we have check vowel or consonant using switch case, Enter any alphabet:. we have press a. it was go to case 1. then the statement was right. then print "Volew". otherwish , print "Consonant"
Step 8 : using getch() function to hold the screen.