In this article we are going to write a C program to check vowels or consonants within the english alphabet.
Table of Contents
vowels are a, e, i, o, and u. In contrast, consonants are all other alphabets excluding vowels. we have to write a C program that accepts a character as input from the user and determines whether the character is a vowel or consonant.
C Program to Check Vowels or Consonants
#include <stdio.h>
void main()
{
char ch;
printf("Enter the character ");
scanf("%c", &ch);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
{
printf("Given character is a vowel");
}
else
{
printf("Given character is a consonant");
}
}
Output
How does the above C Program Work?
- C program asks the user to enter a character and storit e in a variable named
ch
. - After that by using the if and else statements C program determines and prints whether the given character is a vowel or a consonant.
Happy Coding
2 thoughts on “C Program to Check Vowel or Consonant”