basics · beginner · ~15 min

Count vowels

Loop over a string testing membership.

Challenge

Count the lowercase vowels in a string.

Task

Implement int count_vowels(const char *s) that returns how many characters of s are lowercase vowels (a, e, i, o, u). Uppercase letters do not count. No main — the grader calls it.

Input

A NUL-terminated string s.

Output

Returns the number of lowercase vowels, as an int.

Example

count_vowels("hello")    ->   2
count_vowels("aeiou")    ->   5
count_vowels("rhythm")   ->   0

Edge cases

  • A string with no vowels returns 0.

Rules

  • Only lowercase a e i o u count.

Input format

A NUL-terminated string s.

Output format

The number of lowercase vowels, as an int.

Constraints

Only lowercase a, e, i, o, u count.

Starter code

int count_vowels(const char *s) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.