Learn about C program to check vowel or consonant Using If-else in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.
Contents
C program to check vowel or consonant Using If-else
We use two variables in this program: “uppercase” and “lowercase.” If the character is uppercase and has a vowel, uppercase stores 1; otherwise, uppercase stores 0. Similarly, the variable lowercase stores 1 if the letter is lowercase and vowel, else it stores 0.
Program:
#include<stdio.h>
int main()
{
char ch;
char uppercase, lowercase;
printf("Enter any character: ");
scanf("%c", &ch);
uppercase = (ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U');
lowercase = (ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u');
if( uppercase || lowercase )
printf("%c is Vowel.",ch);
else
printf("%c is consonant.",ch);
return 0;
}
Output:
Enter any character: u
u is Vowel.
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Codes :
Absolute value in C without using the predefined function
fabs() function to find absolute value in C