C Program to check the letter is vowel or consonant
Problem: Write a C program to check the letter is vowel or consonant.Solution:
#include <stdio.h>
int main()
{
char ch;
printf("Input a character\n");
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 character\n");
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.
- Take the character as character or %c.
- And in predefined character set there's value of the A, B, C,....Z or a,b,c,...z
- 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.
- That's it.
- 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
No comments:
Post a Comment