C Program To Check Character is Vowel or Consonant

This article is a tutorial on how to write a C program which accepts a character from user and checks whether it is a vowel or a consonant.

C Program to Check whether Character is Vowel or Consonant

/* Aim: Write a C program to accept a character and check whether it is a vowel or a consonant */

#include<stdio.h>
int main()
{
    char character;

    printf("\n Enter a character from alphabets: ");
    scanf(" %c",&character);

    if ((n=='a') || (n=='e') ||(n=='i') || (n=='o') ||(n=='u') || (n=='A') || (n=='E') ||(n=='I') || (n=='O') ||(n=='U'))
        printf("\n The given character '%c' is vowel. \n \n", character);
    else
        printf("\n The given character '%c' is consonant. \n \n", character);

    return 0;
}

Output:

Test Case 1:
 Enter a character from alphabets: a

 The given character 'a' is vowel.

Test Case 2:
 Enter a character from alphabets: i

 The given character 'i' is vowel.

Explanation:

We know that {a, e, i, o, u, A, E, I, O, U} are vowels and all other characters are consonants. Accept a character from user and store it in variable So we use control statement if to check whether given character is vowel, if it not then it is a consonant and displayed the appropriate message.

C program to check character is vowel or not using function

/* Aim: Write a function for the following function prototype
void isVowel(char c) */

#include<stdio.h>

void isVowel(char c); // isVowel Function Prototype

void main()
{
	char c;
	printf("\n Enter any character:- ");
	scanf("%c",&c);
 
	isVowel(c);
}

// isVowel Function

void isVowel(char c)
{

	if(c=='a' || c=='e' || c=='i' || c=='o' || c=='u')
		printf("\n %c is a vowel \n \n",c);
	else
		printf("\n %c is not a vowel \n \n",c);
} 

Output

 Enter any character:- a

 a is a vowel