• In this  program we will discuss about how to check whether a character is vowel or consonant.
  • In English language will be having 5 vowels and 21 consonants.
  • To check entered character is vowel or consonant, first Read input character from user using scanf.
  • There are only 5 vowels(A,E,I,O,U), so we need to check entered character is there in those 5 characters.
  • If it is present then we can say its an vowel, otherwise it is a consonant.
  • While checking we need to consider case sensitivity. So we need to check both uppercase vowels and lower case vowels.
  • Lets see an example program to check whether entered character is vowel or not.

check vowel or consonant in c


Write a program to determine whether the input character is a vowel or consonant or not an alphabet

  1. #include <stdio.h>
  2. //write a program to determine whether the input character is a vowel or consonant or not an alphabet
  3. //c program to check whether a character is vowel or consonant
  4. //www.InstanceofJava.com
  5. int main() {
  6.     char character;
  7.     int lowercaseVowel, uppercaseVowel;
  8.     printf("Enter a character  ");
  9.     scanf("%c", &character);

  10.     // assigns 1
  11.     lowercaseVowel = (character == 'a' || character == 'e' || character == 'i' || character == 'o' || character == 'u');

  12.     // evaluates to 1 if variable c is a uppercase vowel
  13.     uppercaseVowel = (character == 'A' || character == 'E' || character == 'I' || character == 'O' || character == 'U');

  14.     // evaluates to 1 (true) if c is a vowel
  15.     if (lowercaseVowel || uppercaseVowel)
  16.         printf("%c is a vowel.", character);
  17.     else
  18.         printf("%c is a consonant.", character);
  19.    getch();
  20. }


Output:
  1. Enter a character
  2. I
  3. I is an vowel


Instance Of Java

We will help you in learning.Please leave your comments and suggestions in comment section. if you any doubts please use search box provided right side. Search there for answers thank you.
«
Next
Newer Post
»
Previous
Older Post

No comments

Leave a Reply

Select Menu