Skip to main content

ProwessApps

Learn · Practice · Excel

C Program to check the alphabet is vowel or not

C Code Example — Conditional Programs

ADVERTISEMENT

C Program to check the alphabet is vowel or not

Objective

Write a C program to check if an entered alphabet is a Vowel or a Consonant.

Algorithm / Approach

  1. Declare a character variable.
  2. Use scanf("%c", &a) to read a single character.
  3. Use the logical OR operator (||) to check if the character matches any lowercase vowel ('a', 'e', 'i', 'o', 'u').
  4. Use an else if to check against uppercase vowels ('A', 'E', 'I', 'O', 'U').
  5. If none match, print that it is NOT a vowel.
main.c
#include<stdio.h>
int main( ) {
 int a, b,c;
 printf("Enter Values for A : ");
 scanf("%c",&a);
 if(a=='a'||a=='e'||a=='I'||a='o'||a=='u') {
  printf("Character is VOWEL\n");
 }
 else if(a=='A'||a=='E'||a=='I'||a='O'||a=='U') {
  printf("Character is VOWEL\n");
 }
 else {
  printf("Character is NOT VOWEL\n");
 }
 return 0;
}

Expected Output

Enter Values for A : x
Character is NOT VOWEL

Explanation of the Program

  • The Logical OR operator (||) returns true if AT LEAST ONE of its conditions is true.
  • Note: You must compare the variable individually every time (e.g., a == 'a' || a == 'e'). You cannot write a == 'a' || 'e'.
  • A common bug in C is using the assignment operator (=) instead of the equality operator (==) inside an if condition (e.g., a = 'o'). This permanently changes the variable's value and always evaluates to true, breaking the logic.

Complexity

Time Complexity O(1)
Space Complexity O(1)

Common Mistakes

  • Using a single equals sign = instead of double equals == in the if-condition. The code provided actually contains this bug: a='o' and a='O'. This assigns the letter to the variable instead of comparing it!
ADVERTISEMENT