In this post, we will write a C program to check whether the input entered by the user is Vowel or consonant
character(alphabet) entered by the user is Vowel if the character belongs to a small or capital letter, 'A', 'E', 'I', 'O', 'U' or 'a', 'e', 'i', 'o', 'u'. All other alphabets are consonant
#include<stdio.h>
int main()
{
char c;
printf("\n Enter the character:");
scanf("%c",&c);
if(c=='a'|| c=='e' || c=='i'|| c=='o'|| c=='u'|| c=='A'|| c=='E'
|| c=='I'|| c=='O'||c=='U')
{
printf("\n %c is a vowel",c);
}
else
{
printf("%c is a consonant",c);
}
return 0;
}
Enter the character:U U is a vowel
In this program, the user must take input alphabet only. if the user enters a non-alphabet character, the output will be a character as a consonant. to fix the above problem, see the below program
#include<stdio.h>
int main()
{
char c;
printf("\n Enter the character");
scanf("%c",&c);
if(c>='a' && c<='z' || c>='A' && c<='Z')
{
if(c=='a'|| c=='e' || c=='i'|| c=='o'|| c=='u'|| c=='A'|| c=='E'
|| c=='I'|| c=='O'||c=='U')
{
printf("\n %c is a vowel",c);
}
else
{
printf("\n %c is a consonant",c);
}
}
else {
printf("\n %c is a neither Vowel not constant",c);
}
}
Enter the character:a a is a vowel
Enter the character:Enter the character:d d is a consonant
c
.