Checking if a character is a vowel using a Switch Statement in C


This program is a simple program that takes an input of a character and checks if it's a vowel or not using a switch statement.

  • The program starts by including the stdio.h header file, which contains the declarations of the functions used in the program.
  • In the main function, the program declares a character variable "x" to store the character entered by the user.
  • It uses the printf function to prompt the user to enter a character and uses the scanf function to read the input and store it in the "x" variable.
  • The program then uses a switch statement to check the value of "x" and match it with the cases in the switch statement. Each case has a corresponding vowel alphabet.
  • In the case where the character entered by the user matches the case, the program will print the message " is a vowel alphabet" using the printf function.
  • In the default case, if the character entered by the user does not match any of the cases, the program will print " is not a vowel"
  • Finally, it returns 0 to indicate that the program has executed successfully.

Source Code

#include <stdio.h>
int main()
{
char x;
printf("\n Enter the alphabet :");
scanf("%c",&x);
switch(x)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
  printf("\n%c is a vowel alphabet",x);
break;
default:
  printf("\n%c is not a vowel",x);
break;
}
return 0;
}
To download raw file Click Here

Output

Enter the alphabet:a
a is a vowel alphabet

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C