C Program to check the letter is vowel or consonant

Problem:  Write a C program to check the letter is vowel or consonant.

Solution:

C Program to check the letter is vowel or consonant

C code to check vowel or consonant using if-else

#include <stdio.h>

int main()
{
char ch;

printf("Input a charactern");
scanf("%c", &ch);

if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' &&ch <= 'Z')) {
if (ch=='a' || ch=='A' || ch=='e' || ch=='E' || ch=='i' || ch=='I' || ch=='o' || ch=='O' || ch== 'u' || ch=='U')
printf("%c is a vowel.n", ch);
else
printf("%c is a consonant.n", ch);
}
else
printf("%c is neither a vowel nor a consonant.n", ch);

return 0;
}

C code to check vowel or consonant using switch-case

#include <stdio.h>
int main()
{
char ch;

printf("Input a charactern");
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("%c is a vowel.n", ch);
break;
default:
printf("%c is not a vowel.n", ch);
}

return 0;
}

Demonstration:
This is a simple code to check if the taken character is a vowel or not.

  1. Take the character as character or %c.
  2. And in predefined character set there’s value of the A, B, C,….Z or a,b,c,…z
  3. So check if the character is A, E, I, O, U or a,e,i,o,u. If the characters are these, then just say this is vowel otherwise say it is a consonant.
  4. That’s it.
  5. Implement the C Code cow.
Tags:
C Program to check the letter is vowel or consonant, Vowel checking code, Check if the letter is vowel or consonant

By Maniruzzaman Akash

Maniruzzaman Akash is a freelance web developer with most popular Laravel PHP frameork and Vue JS

Leave a Reply

Your email address will not be published. Required fields are marked *