Learn about C Program to Check Vowel or Consonant using predefined function 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 predefined function
tolower(c)
: If the c is a capital letter, it returns the lowercase equivalent; otherwise, it returns c.
toupper(c)
: It gives you the uppercase version. If the c is a lowercase letter, it yields c; otherwise, it returns c.
When using the tolower() function, we must only look for lowercase letters and not capital letters. We can now utilise an if-else or switch-case statement.
Source code:
#include<stdio.h>
#include<ctype.h>
int main()
{
char ch;
int result;
printf("Enter any character: ");
scanf("%c",&ch);
ch = tolower(ch);
result = (ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u');
switch(result)
{
case 1:
printf("Vowel\n");
break;
case 0:
printf("Consonant\n");
break;
default:
printf("Invalid character\n");
break;
}
return 0;
}
Output:
Enter any character: A
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 :
Check Character is Vowel or Consonant using Switch case
C program to check vowel or consonant Using If-else