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
hello world
3
A line of lowercase English letters and spaces is given.
Print how many vowels (a, e, i, o, u) it contains.
hello world
3
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.
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).
s = input()print(sum(1 for c in s if c in "aeiou"))const s = require("fs").readFileSync(0, "utf8").split("\n")[0];console.log([...s].filter((c) => "aeiou".includes(c)).length);import { readFileSync } from "node:fs";const s: string = readFileSync(0, "utf8").split("\n")[0];console.log([...s].filter((c) => "aeiou".includes(c)).length);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); }}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); }}#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';}#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;}s = Console.ReadLine();count = 0;foreach (c in s){ if (c == "a" || c == "e" || c == "i" || c == "o" || c == "u") { count++; }}Console.WriteLine(count);