C Program to determine whether given character is vowel or not

      This program checks whether given character is vowel or not ( i.e., ‘a’ or ‘e’ or ‘i’ or ‘o’ or ‘u’ or ‘A’ or ‘E’ or ‘I’ or ‘O’ or ‘U’ or ‘y’ or ‘Y’ ) or not.
Since program needs to check for multiple conditions, All those conditions are simply performed using switch case.
So if a given character is not either of them then it implies that given character is not a vowel.

vowel or not program in c



Source Code:

#include<stdio.h>
int main(void)
{
	char c;
	printf("Enter a character: ");
	scanf("%c", &c);
	switch(c)
	{
		case 'a': case 'A':
		case 'e': case 'E':
		case 'i': case 'I':
		case 'o': case 'O':
		case 'u': case 'U':
				printf("%c is always a vowel!\n", c);
				break;
		case 'y': case 'Y':
				printf("%c is sometimes a vowel!\n", c);
				break;
		default:
				printf("%c is not a vowel!\n", c);

	}
	return 0;
}


edit-code-image

Sample Test cases:

1. Enter a character: A
   A is always a vowel!

2. Enter a character: D
   D is not a vowel!

3. Enter a character: Y
   Y is sometimes a vowel!

Explanation:

Step 1: Program reads a character from the user using scanf() function.

Step 2: It checks whether given character is either ‘a’ or ‘e’ or ‘i’ or ‘o’ or ‘u’ or ‘A’ or ‘E’ or ‘I’ or ‘O’ or ‘U’ using switch case.
So if any of these cases are true then it implies that given character is vowel.
So program prints “character(given character)is always vowel!”.

Step 3: It also checks whether given character is either ‘y’ or ‘Y’. If this case is true
program prints “character(given character) is somettimes a vowel!”.

Step 4: If given character is not either of them then it implies that given character is not
a vowel so program prints ” character(given character) is not a vowel!”.

More Insights:

1. Vowels in English alphabets.

2. Semivowels in English alphabets.

3. Is the letter ‘Y’ a vowel or a consonant ?
Explore C Programs:C Programs