- 1C Hello World Program
- 2C Program to Print Your Own Name
- 3C Program to Print an Integer Entered by the User
- 4C Program to Add Two Numbers
- 5C Program to Multiply Two Floating‑Point Numbers
- 6C Program to Print the ASCII Value of a Character
- 7C Program to Swap Two Numbers
- 8C Program to Calculate Fahrenheit to Celsius
- 9C Program to Find the Size of int, float, double and char
- 10C Program - Add Two Complex Numbers
- 11C Program - Find Simple Interest
- 12C Program - Find Compound Interest
- 13C Program - Area And Perimeter Of Rectangle
- 14C Program - Check Whether a Number is Positive, Negative, or Zero
- 15C Program - Check Whether Number is Even or Odd
- 16C Program - Check Whether a Character is Vowel or Consonant
- 17C Program - Find Largest Number Among Three Numbers
- 18C Program - Calculate Sum of Natural Numbers
- 19C Program - Print Alphabets From A to Z Using Loop
- 20C Program - Make a Simple Calculator
- 21C Program - Generate Multiplication Table
- 22C Program - Reverse a Number
- 23C Program - Check whether the input number is a Neon Number
- 24C Program - Find All Factors of a Natural Number
C Program – Check Whether a Character is Vowel or Consonant - If/Else & Switch
Vowel or Consonant Using If-Else
#include <stdio.h>
int main() {
char ch;
printf("Enter an alphabet: ");
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("%c is a vowel\n", ch);
} else {
printf("%c is a consonant\n", ch);
}
return 0;
}
Enter an alphabet: e
e is a vowel
This method compares the input character against all vowels (both lowercase and uppercase). If none match, the character is considered a consonant.
Vowel or Consonant Using Switch
#include <stdio.h>
int main() {
char ch;
printf("Enter an alphabet: ");
scanf(" %c", &ch);
switch(ch) {
case 'a': case 'e': case 'i': case 'o': case 'u':
case 'A': case 'E': case 'I': case 'O': case 'U':
printf("%c is a vowel\n", ch);
break;
default:
printf("%c is a consonant\n", ch);
}
return 0;
}
Enter an alphabet: x
x is a consonant
A switch statement can simplify multi-branch checks. By grouping vowel cases together, the program prints a message when any vowel is matched and uses the default branch for consonants.
⬅ Previous TopicC Program - Check Whether Number is Even or Odd
Next Topic ⮕C Program - Find Largest Number Among Three Numbers
Next Topic ⮕C Program - Find Largest Number Among Three Numbers
Comments
Loading comments...