C program to check a character is vowel or consonant

C program to check whether a character is vowel or consonant

C program to check whether a character is vowel or consonant. Both upper case and lower case character are covered in this program.For example user enter a character A  output will show it is vowel.


#include<stdio.h>
#include<conio.h>

void main()
{
char ch;

printf("enter a character\n");
scanf("%c",&ch);

if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U') 
{
printf("%c is a vowel");
}
else
{
printf("%c is a Consonant");
}
getch();
}

Output:-



Check vowel with switch statements

Using switch statements  to check the enter character is vowel or not.

#include<stdio.h>
#include<conio.h>

void main()
{
char ch;
printf("enter your character");
scanf("%c",&ch);

switch(ch)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':

printf(" enter character is vowel");
break;
default:
printf("enter character is consonant");
break;
}
getch();
}

Output:-




No comments:

Post a Comment