Vowel program in c

Written by

Namrata Jangid

Check Vowel Program

We can check if a character entered by the user is a vowel or a consonant by using an if-else statement or a switch case block.

Code for checking for vowels and consonants by using if-else

 
#include <stdio.h>

int  main()

{

char  ch;

printf("Enter a character:");

scanf("%c", & amp; ch);

if  (ch == 'a'  || ch == 'A'  || ch == 'e'  || ch == 'E'  || ch == 'i'  || ch == 'I'  || ch == 'o'  || ch == 'O'  || ch == 'u'  || ch == 'U') //checking if the character is a vowel

  printf("%c is a vowel.\n", ch);

else

  printf("%c is a consonant.\n", ch);

return  0;

}

The output for the above code is:

 
Enter a character: A

A is a vowel.

Code for checking for vowels and consonants by using switch case:

 
#include <stdio.h>

int  main()

{

char  ch;

printf("Enter a character: ");

scanf("%c", & amp; ch);

switch (ch)

{

  //checking if the character is a vowel in all the cases below

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 isn't a vowel.\n", ch);

}

return  0;

}

The output for the above code is:

 
Enter a character:  A

A is a vowel.

Vowel program in c