{ }codelper
iterating stringsmembership testP0009

Count the vowels

A line of lowercase English letters and spaces is given.
Print how many vowels (a, e, i, o, u) it contains.

Input
length 1 to 200
Output
number of vowels
Example 1 · stdin
hello world
stdout
3
main.py
Input (stdin)

When you run, these lines are fed to input()/stdin in order (the program doesn't stop to ask).

$ Ready

Open this on a computer to write and run code. On mobile you can read the problem and the solutions.

In other languagesShow solutions by language · 8 languages

Asking "is this a vowel?": Python c in "aeiou", JavaScript "aeiou".includes(c), Java "aeiou".indexOf(c) >= 0, C strchr("aeiou", c).
To read a whole line with spaces use C++ getline, Java nextLine, C fgets (cin >> and scanf("%s") stop at a space).

Pythonmain.py · 2 lines
s = input()print(sum(1 for c in s if c in "aeiou"))
JavaScriptmain.js · 2 lines
const s = require("fs").readFileSync(0, "utf8").split("\n")[0];console.log([...s].filter((c) => "aeiou".includes(c)).length);
TypeScriptmain.ts · 3 lines
import { readFileSync } from "node:fs";const s: string = readFileSync(0, "utf8").split("\n")[0];console.log([...s].filter((c) => "aeiou".includes(c)).length);
JavaMain.java · 10 lines
import java.util.Scanner; public class Main {    public static void main(String[] args) {        String s = new Scanner(System.in).nextLine();        int count = 0;        for (char c : s.toCharArray()) if ("aeiou".indexOf(c) >= 0) count++;        System.out.println(count);    }}
C#Main.cs · 12 lines
using System; class Program{    static void Main()    {        string s = Console.ReadLine();        int count = 0;        foreach (char c in s) if ("aeiou".Contains(c)) count++;        Console.WriteLine(count);    }}
C++main.cpp · 11 lines
#include <iostream>#include <string> int main() {    std::string s;    std::getline(std::cin, s);    int count = 0;    for (char c : s)        if (std::string("aeiou").find(c) != std::string::npos) count++;    std::cout << count << '\n';}
Cmain.c · 12 lines
#include <stdio.h>#include <string.h> int main(void) {    char s[256];    fgets(s, sizeof s, stdin);    int count = 0;    for (int i = 0; s[i] && s[i] != '\n'; i++)        if (strchr("aeiou", s[i])) count++;    printf("%d\n", count);    return 0;}
Craykonmain.cray · 10 lines
s = Console.ReadLine();count = 0;foreach (c in s){    if (c == "a" || c == "e" || c == "i" || c == "o" || c == "u")    {        count++;    }}Console.WriteLine(count);