Remove Consonants in C, C++, Java & Python – Code with Explanation & Examples in Short and Simple

   

C Program

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main() {
    char str[100], res[100];
    int i, j = 0;
    printf("Enter a string: ");
    gets(str);

    for (i = 0; str[i] != '\0'; i++) {
        char c = tolower(str[i]);
        if (c=='a' || c=='e' || c=='i' || c=='o' || c=='u' || c==' ')
            res[j++] = str[i];
    }
    res[j] = '\0';

    printf("String after removing consonants: %s", res);
    return 0;
}

C Output

Input:
hello world

Output:
eo o


C++ Program

#include <iostream>
#include <string>
using namespace std;

int main() {
    string str, res = "";
    cout << "Enter a string: ";
    getline(cin, str);

    for (char c : str) {
        char lower = tolower(c);
        if (lower=='a'||lower=='e'||lower=='i'||lower=='o'||lower=='u'||c==' ')
            res += c;
    }
    cout << "String after removing consonants: " << res;
    return 0;
}

C++ Output

Input:
programming is fun

Output:
oai i u


JAVA Program

import java.util.Scanner;

public class RemoveConsonants {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter a string: ");
        String str = sc.nextLine();
        String res = "";

        for (char c : str.toCharArray()) {
            char lower = Character.toLowerCase(c);
            if ("aeiou ".indexOf(lower) != -1)
                res += c;
        }
        System.out.println("String after removing consonants: " + res);
    }
}

JAVA Output

Input:
java developer

Output:
aa eeoe


Python Program

s = input("Enter a string: ")
res = "".join([c for c in s if c.lower() in "aeiou "])
print("String after removing consonants:", res)

Python Output

Input:
python language

Output:
o auae


In-Depth Explanation
Example
When we take the phrase "hello world", consonants such as h, l, w, r, l, d are stripped off. We retain only vowels (a, e, i, o, u) and spaces. Thus the output is "eo o". This is useful in concentrating on vowels only, which is typically helpful in text-processing issues.

Real-Life Analogy
Suppose you play a song and you eliminate all instruments but the voice of the singer. What you have left is just the vocal tone (vowels) and consonants are like the background instruments you chose to muffle. In the same way, consonants are removed in our program, leaving us with just vowels and spaces. 

Why It Matters
Removing consonants may look simple, but it is a very powerful string manipulation technique. It shows us how to scan through each character of a string, make decisions based on conditions, and build a new string. This logic is fundamental in data cleaning, cryptography, and natural language processing. For example, text-to-speech systems sometimes emphasize vowels while ignoring consonants for pronunciation models.

Learning Insights
This problem teaches beginners how to:

Iterate over strings character by character.

Apply conditions (if statements) to determine which characters to retain.

Operate on string concatenation or constructing new outcomes.

Have knowledge of ASCII manipulation (in C) or built-in functions such as tolower(), .indexOf(), or Python's in.

It also covers the concept of filtering data, used extensively in actual programming. For instance, filtering logs to display only errors, filtering database queries, or cleansing user inputs by truncating unwanted characters.

Real-World Applications
Consider creating a text-based game where you wish to make puzzles by displaying only vowels of a word and having the player supply the full word. Another instance is password masking, where letters are obfuscated or omitted. Such an idea is also useful when dealing with speech recognition or when implementing search algorithms that occasionally deal with vowels for phonetic matching.

Interview Relevance
In coding interview settings, string questions such as this are commonly asked since they assess a candidate's capability to work efficiently with strings, properly handle conditions, and contemplate edge cases (such as spaces, uppercase, or null strings). An interviewer can complicate this question by requesting the removal of consonants, vowels, digits, or even frequency analysis of the remaining characters.
Learning how to delete consonants from a string in C, C++, Java, and Python lays a solid foundation in string manipulation, conditional statements, and input-output handling. Beginners doing this kind of program not only enhance their programming skills but also prepare themselves for programming interviews, competitive coding contests, and real-world text processing tasks. Whether you have small tasks or big projects with data cleaning and natural language processing, knowing how to filter out characters from a string is a major programming skill.