AlgoMaster Logo

Vowel or Consonant

Last Updated: June 7, 2026

easy
3 min read

Understanding the Problem

The task is a membership test. Five letters are vowels: a, e, i, o, and u. The other twenty-one are consonants. Is the given letter one of those five? If yes, it is a vowel; if no, a consonant.

The complication is case. A and a are both vowels, but a computer treats them as different characters with different codes. Rather than list all ten vowel forms, normalize the input first. Convert the character to lowercase, and you compare against five letters.

Key Constraints:

  • The input is a single letter → You are testing one character, not a word, so there is no looping involved.
  • Case can vary → Normalize to lowercase (or uppercase) before comparing, so E and e are treated the same.
  • Only five letters are vowels → Anything that is not one of the five vowels is a consonant by default, so the consonant case is the catch-all.

Approach 1: Direct Comparison

Intuition

The most literal way to express "is this one of these five letters" is a chain of equality checks joined by OR. Lowercase the character, then ask whether it equals a, e, i, o, or u. If any is true, the letter is a vowel. If all five fail, it falls through to consonant.

Algorithm

  1. Convert ch to lowercase so case no longer matters.
  2. Compare the lowercased character against each of the five vowels.
  3. If it matches any vowel, return "Vowel".
  4. Otherwise return "Consonant".

Example Walkthrough

Input:

0
E
ch

The input is the uppercase letter E. Lowercasing it gives e. Now compare against the vowels: it does not equal a, but it does equal e, so the OR chain short-circuits to true on the second comparison. The letter is a vowel.

0
V
1
o
2
w
3
e
4
l
output

Code

Approach 2: Switch on the Character

Intuition

Dispatching a single variable against a fixed list of constants reads more directly as a switch than as a chain of OR comparisons. List the five vowel cases together, let them share one outcome, and treat everything else as the default.

The behavior is identical to the comparison chain. The difference is readability: the five vowels line up as labeled cases, and the default branch makes the "everything else is a consonant" rule explicit. You still normalize to lowercase first so you need five case labels instead of ten.

Algorithm

  1. Convert ch to lowercase.
  2. Switch on the character.
  3. For the cases a, e, i, o, and u, return "Vowel".
  4. For the default case, return "Consonant".

Example Walkthrough

Input:

0
b
ch

The input is b, which is already lowercase. The switch looks for a matching case among the five vowels. None of them is b, so control falls to the default branch, which returns "Consonant".

0
C
1
o
2
n
3
s
4
o
5
n
6
a
7
n
8
t
output

Code