Write c program to accept a character from user and check whether the character is a vowel or consonant.
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
//declaration of character
char ch[10];
//accept character
printf("\nEnter any character: ");
gets(ch);
//compare 2 characters using strcmp function()
//The strcmp() function is used to compare two strings two strings
if(strcmp(ch,"a")==0||strcmp(ch,"A")==0)
{
printf("\ncharacter is vowel.");
}
else if(strcmp(ch,"e")==0||strcmp(ch,"E")==0)
{
printf("\ncharacter is vowel.");
}
else if(strcmp(ch,"i")==0||strcmp(ch,"I")==0)
{
printf("\ncharacter is vowel.");
}
else if(strcmp(ch,"o")==0||strcmp(ch,"O")==0)
{
printf("\ncharacter is vowel.");
}
else if(strcmp(ch,"u")==0||strcmp(ch,"U")==0)
{
printf("\ncharacter is vowel.");
}
else
{
printf("\ncharacter is consonant.");
}
return(0);
getch();
}
0 Comments