✓ Link copied to clipboard
C 📅 July 3, 2026 ⏱ 4 min read

C Program to Check Whether a Character is a Vowel or Consonant

C Program to Check Whether a Character is a Vowel or Consonant

When you're diving into C, checking if a character is a vowel or consonant is a classic beginner task. For example, type in 'a' and the program should say it's a vowel. But enter 'b', and you'll get a consonant. Let's see how we do this with if-else statements.

Prerequisites for the Vowel or Consonant Program in C

Before we start coding, make sure you understand these concepts:

  • The if-else statement in C for decision making
  • Character handling using char data type
  • Input/Output functions like scanf and printf
  • Any C compiler such as GCC 9 or newer — or just run it in the EduSeekho online compiler

Source Code of C Program to Check Whether a Character is a Vowel or Consonant

Below is the full C code to check if a character is a vowel or consonant.

check_char.cC▶ Run
#include <stdio.h>

int main() {
    char ch;
    printf("Enter a character: ");
    scanf(" %c", &ch);

    // Check if the character is a vowel
    if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||
        ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U') {
        printf("The character is a vowel.\n");
    } else {
        printf("The character is a consonant.\n");
    }

    return 0;
}

Try this code yourself — free

Run it in the EduSeekho online compiler. No setup needed.

▶ Open Compiler

Output of the Vowel or Consonant Program

Here's what you should see when you enter 'a' as input:

OUTPUTshell▶ Run
Enter a character: a
The character is a vowel.
Output of C Program to Check Whether a Character is a Vowel or Consonant
Output of C Program to Check Whether a Character is a Vowel or Consonant

Algorithm to Check Vowel or Consonant in C

The program reads a character and checks if it's a vowel by comparing it against known vowel characters. Here is how it works step by step:

  1. Read the character from the user.
  2. Check if the character is equal to any of the vowels ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U').
  3. If it matches, print "The character is a vowel."
  4. If not, print "The character is a consonant."
flowchart TD
  A([Start]) --> B[/Read character/]
  B --> C{Is character vowel?}
  C -->|Yes| D[Print "Vowel"]
  C -->|No| E[Print "Consonant"]
  D --> F([End])
  E --> F
Flowchart: the algorithm step by step

How the C Program to Check Vowel or Consonant Works

Let's break down the code to understand what each part does.

  • #include <stdio.h>: Includes the standard input-output library necessary for printf and scanf.
  • char ch;: Declares a character variable to store user input.
  • printf("Enter a character: ");: Prompts the user to enter a character.
  • scanf(" %c", &ch);: Reads the input character.
  • The if statement checks if ch is any of the vowels (both uppercase and lowercase).
  • If true, printf("The character is a vowel.\n"); outputs that it's a vowel.
  • Otherwise, printf("The character is a consonant.\n"); indicates it's a consonant.
  • return 0;: Indicates successful program termination.
🧠

Quick Quiz — test your understanding

Tap an option to check your answer

What is a potential issue if the input character is uppercase?

🎉Correct! Uppercase vowels won't match lowercase checks.
🤔Not quite. Think about how case sensitivity affects character comparison.

How Fast Is the Vowel or Consonant Program in C?

The time and space complexity of this program are straightforward.

Time Complexity: O(1). The program checks a constant number of conditions (10 vowels) regardless of input, like if conditions for each vowel.

Space Complexity: O(1). It uses only one character variable ch, irrespective of input size.

⚠️

Common mistake: Be careful with uppercase and lowercase vowels; ensure both are checked.

Key takeaway: Always think about case sensitivity when working with character data.

FAQs About Checking Vowel or Consonant in C

Here are some common questions students have about this program.

Include uppercase letters in your if checks, like 'A', 'E', 'I', 'O', 'U'.
Sure, a switch statement with cases for each vowel works.
They'll be counted as consonants in this program.
Think about using functions to keep the logic separate from the main program.
You can, but you'll have to add extra logic to handle each character in the string.

If you found this program helpful, check out these related programs:

Conclusion

Think about extending this code to handle strings, not just single characters. It pops up in text-processing apps all the time. You might also want to explore string manipulation in C next. This opens up more advanced C programming tasks.

For more practice, check out the C programming quiz or write and test your code in the C online compiler.