Print Vowels in a String2 months ago

The program must accept a string S as the input. The program must print all the vowels in the string S as the output.
Note: At least one vowel is always present in the string S.

Boundary Condition(s):
1 <= Length of S <= 99

Input Format:
The first line contains S.

Output Format:
The first line contains the vowels in the string S.

Example Input/Output 1:
Input:
applE cArT

Output:
aEA

Explanation:
The vowels in the string applE cArT are a, E and A.
Hence the output is aEA

Example Input/Output 2:
Input:
15V AAA size battery #2Nos

Output:
AAAieaeo

The below video explains the logic and the implementation in C programming language to print all the vowels in a given string.

#include <stdio.h>
#include <stdlib.h>

int isVowel(char ch)
{
    ch = tolower(ch);
    return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
}

int main()
{
    char str[100];
    scanf("%[^\n\r]", str);
    for(int index = 0; str[index]; index++)
    {
        if(isVowel(str[index]))
        {
            printf("%c", str[index]);
        }
    }
}

 

#include <iostream>

using namespace std;

int isVowel(char ch)
{
    ch = tolower(ch);
    return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
}

int main()
{
    string str;
    getline(cin, str);
    for(int index=0; index<str.length(); index++)
    {
        if(isVowel(str[index]))
        {
            cout << str[index];
        }
    }
    return 0;
}

 

import java.util.Scanner;

public class Hello {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        str = str.replaceAll("[^aeiouAEIOU]", "");
        System.out.println(str);
    }
}

 

import re
strval = input().strip()
print(re.sub("[^aeiouAEIOU]+", "", strval))