Skip to main content

ProwessApps

Learn · Practice · Excel

WAP to check the alphabet is vowel or not.

C++ Code Example — Conditional Programs

ADVERTISEMENT

WAP to check the alphabet is vowel or not.

Objective

Write a C++ program to check if an alphabet character is a vowel or a consonant.

Algorithm / Approach

  1. Read a character a.
  2. Check for lowercase vowels using the Logical OR operator: if (a=='a' || a=='e' || ...).
  3. Check for uppercase vowels using else if (a=='A' || a=='E' || ...).
  4. If none match, use an else to declare it a consonant.
main.cpp
#include<iostream>
using namespace std;
int main() {
 char a;
 cout<<"Enter a Character: ";
 cin>>a;
 if(a=='a' ||a=='e' ||a=='i' ||a=='o' ||a=='u') {
  cout<<"Character is vowel \n";
 }
 else if(a=='A' ||a=='E' ||a=='I'||a=='O' ||a=='U') {
  cout<<"Character is vowel \n";
 }
 else {
  cout<<"Character is NOT vowel \n";
 }
return 0;
}

Expected Output

Enter a Character: E
Character is vowel

Explanation of the Program

  • The Logical OR operator (||) is the counterpart to the Logical AND operator.
  • For an || expression to be considered true, ONLY ONE of the conditions needs to be true. This is perfect for checking if a variable matches any value within a specific list.

Complexity

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