All Even Vowels

🎯 Array Hurdle

All Even Vowels

Difficulty: ⚫⚫◯◯

Tags: array, strings, counting, parity

Hurdle: Passing this question is sufficient to pass the arrays hurdle.

Description

Write a function all_even_vowels that takes an array of strings with exactly size strings. Each string is terminated by the null terminator ('\0') character.

The function should return:

  • 1 if every string contains an even number of vowels
  • 0 if any string has an odd number of vowels

Important: Zero is considered an even number.

Vowels: a, e, i, o, u (and their uppercase versions A, E, I, O, U)

Examples

Example 1: All Even

"hello"    // 2 vowels (e, o) -> EVEN ✓
"apple"    // 2 vowels (a, e) -> EVEN ✓
"book"     // 2 vowels (o, o) -> EVEN ✓

Output: 1

Explanation: Every string has an even number of vowels.

Example 2: One Odd

"hello"    // 2 vowels (e, o) -> EVEN ✓
"cat"      // 1 vowel (a)     -> ODD ✗
"book"     // 2 vowels (o, o) -> EVEN ✓

Output: 0

Explanation: "cat" has an odd number of vowels (1).

Example 3: Zero is Even

"xyz"      // 0 vowels -> EVEN ✓
"bcd"      // 0 vowels -> EVEN ✓
"fgh"      // 0 vowels -> EVEN ✓

Output: 1

Explanation: Every string has zero vowels, and zero is an even number.

Example 4: First Row Odd

"cat"      // 1 vowel (a)     -> ODD ✗
"hello"    // 2 vowels (e, o) -> EVEN ✓
"book"     // 2 vowels (o, o) -> EVEN ✓

Output: 0

Example 5: Uppercase Vowels

"HELLO"    // 2 vowels (E, O) -> EVEN ✓
"APPLE"    // 2 vowels (A, E) -> EVEN ✓
"BOOK"     // 2 vowels (O, O) -> EVEN ✓

Output: 1

Explanation: Uppercase vowels count too.

Example 6: All Odd

"cat"      // 1 vowel -> ODD ✗
"dog"      // 1 vowel -> ODD ✗
"pig"      // 1 vowel -> ODD ✗

Output: 0

Function Signature

int all_even_vowels(int size, char *array[MAX_ROWS]);

Constants

#define MAX_ROWS 100

Constraints

  • Uppercase and lowercase vowels all count as vowels.
  • You can assume there will be at least one string.
  • Zero vowels is considered an even count.
  • Each string contains at most 100 characters.
  • Return 1 for true, 0 for false.
  • Do not modify the array provided.
  • Do not call scanf, getchar, or fgets.
  • Do not call printf.

Hints

  • Create a helper function to count vowels in a single string.
  • A number is even if count % 2 == 0.
  • Return 0 immediately when you find a string with an odd count.
  • If you check all strings and none have odd counts, return 1.

Testing

./all-even-vowels hello apple book
1

./all-even-vowels hello cat book
0

./all-even-vowels xyz bcd fgh
1

./all-even-vowels cat hello book
0

./all-even-vowels HELLO APPLE BOOK
1

./all-even-vowels cat
0

./all-even-vowels hello
1
Code Editor
Output
Run your code to see output here...