C Programming language

adplus-dvertising
C Program example: Input a character and check it vowel or not
Previous Home Next
Input a character and check it vowel or not

In this example we first include two required headers #include <stdio.h> and #include <conio.h>. These are included to use methods(also call functions) defined into these header files.

Here we are using five methods main() method ,clrscr() method ,printf() method, scanf method and getch() method.

In this we are using if-else to check vowel or consonant .First enter a alphabet then compare it with five vowels(a,e,i,o,u) if it is true then print vowel else print consonant. Here we are using OR (||) operator to check multiple conditions at a time in if.

/* Input a character and check it vowel or not */

#include<stdio.h>
#include<stdio.h>
void main()
{
	char ch;
	clrscr();
	printf("Enter a alphabet \t:");
	scanf("%c",&ch);
	if(ch=='a'||ch=='A'||ch=='e'||ch=='E'
	||ch=='i'||ch=='I'||ch=='o'||ch=='O'||ch=='u'||ch=='U')
		printf("\n\nIt is a vowel");
	else
		printf("\n\nIt is a consonant");
	getch();
}
Output :

Enter a alphabet : a

It is a vowel

Previous Home Next