character is vowel or not

C program to determine whether the character is vowel or not.


Program

#include<stdio.h>
#include<conio.h>
void main()
{
   	char ch;

	printf("Enter a character\t:");
	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("Entered character is a vowel");
	}
	else if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
    {
        printf("Entered character is a consonant");
    }
	else
	{
		printf("Entered character is not an alphabet");
	}

	getch();
}

Output

********** Run1 **********

Enter a character       :e
Entered character is a vowel


********** Run2 **********

Enter a character       :r
Entered character is a consonant


********** Run3 **********

Enter a character       :6
Entered character is not an alphabet

Explanation

To check whether a character is a vowel, we have to check for both uppercase and lowercase vowels i.e. a,e,i,o,u,A,E,I,O and U
Condition for checking is
if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
Note that Character in C is represented inside single quote. Do not forget to add single quote whenever checking for character constant.

If character is alphabet but not vowel then it is a consonant.
Condition for checking consonant is
(ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')
Note that, in this case, condition for constant checking must follow the condition for vowel checking. Because, first of all an alphabet is checked for vowel and if it is not a vowel then it is checked for consonant without any exclusions.
If we have to first check the condition for consonant, then we have to explicitly exclude all the vowels in the condition.

If it is neither vowel nor consonant, then it is not an alphabet.

Program

#include<stdio.h>
#include<conio.h>
void main()
{
    char ch;

    printf("Enter a character\t:");
    scanf("%c",&ch);
    if(ch == 97 || ch == 101 || ch == 105 || ch == 111 || ch == 117 || ch == 65 || ch == 69 || ch == 73 || ch == 79 || ch == 85)
    {
		printf("Entered character is a vowel");
    }
    else if((ch >= 97 && ch <= 122) || (ch >= 65 && ch <= 90))
    {
        printf("Entered character is a consonant");
    }
    else
    {
 		printf("Entered character is not an alphabet");
    }

    getch();
}

Output

********** Run1 **********

Enter a character       :I
Entered character is a vowel


********** Run2 **********

Enter a character       :h
Entered character is a consonant


********** Run3 **********

Enter a character       :+
Entered character is not an alphabet

Explanation

Internally characters in C are represented by an integer value known as ASCII value. We can also use ASCII value of a character to check vowels and consonants.

ASCII value of A=65, E=69, I=73, O=79, U=85, a=97, e=101, i=105, o=111, u=117.
So, instead of checking condition if(ch=='a' || ch=='e' || ... ) we can use,
if(ch == 97 || ch == 101 || ch == 105 || ch == 111 || ch == 117 || ch == 65 || ch == 69 || ch == 73 || ch == 79 || ch == 85)