Press "Enter" to skip to content

This is a simple C program to check whether the given character is a vowel or not. In English, the letters (sounds) A, E, I, O, U are considered as vowels.
Here we can solve the problem using if – else and switch statements.



Program using If – Else Statement:

In this program we consider both small and capital letters. So we included both case letters inside a single if statements. If the entered letter match the given set of letters, then print it as a vowel, else that should not a vowel.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
char cletter;
printf("Enter a letter :");
scanf("%c",&cletter);
 if(cletter =='A' || cletter == 'a' || cletter =='E' || cletter == 'e' || cletter == 'I' || cletter == 'i' || cletter == 'O' || cletter == 'o' || cletter == 'U' || cletter == 'u')
     printf("It is a vowel");
else
     printf("Not a vowel, it is a consonant");
 getch();
}

Using Switch Case:

Switch case gets the entered character. There are 5 types of case to check whether the given character is a vowel or not. Default case works if and only if the given character does not match any of these cases.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
char cletter;
printf("Enter a letter :");
scanf("%c",&cletter);
switch(cletter)
{
case 'a':
  printf("It is a vowel");
  break;
case 'e':
  printf("It is a vowel");
break;
case 'i':
printf("It is a vowel");
break;
case 'o':
printf("It is a vowel");
  break;
case 'u':
printf("It is a vowel");
break;
default:
printf("it is a consonant");
}
getch();
}

Instead of writing separate cases with same message of printf, you can combine all cases except default.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h> 
void main()
{
char cletter;
printf("Enter a letter :");
scanf("%c",&cletter);
switch(cletter)
{
  case 'a':
  case 'e':
  case 'i':
  case 'o':
  case 'u':
  printf("It is a vowel");
  break;
default:
   printf("it is a consonant");
}
getch();
}

Considering both Upper and lower case
Her you need to import directory file ‘ctype.h’. |That supports convert between capital and small cases.

#include<stdio.h>
#include<conio.h>
#include<stdlib.h> 
#include<ctype.h> void main()
{
char cletter;
printf("Enter a letter :");
scanf("%c",&cletter);
cletter = tolower(cletter);
switch(cletter)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
printf("It is a vowel");
break;
default:
printf("Not a vowel");
}
getch();
}

Sample Output:

Check Whether the given Character is Vowel or Not in C

Be First to Comment

Leave a Reply

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

%d bloggers like this: