2026-08-24
count_vowels.c
#include <string.h>
int count_vowels(const char *s) {
/* write this: count how many of 'a','e','i','o','u' appear in s */
}
count_vowelsを実装してください。NUL終端文字列sの中にa、e、i、o、u(小文字のみ)がいくつ含まれるかを返します。
Reference
int count_vowels(const char *s) {
int count = 0;
for (size_t i = 0; s[i] != '\0'; i++) {
char c = s[i];
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
count++;
}
}
return count;
}
1回の走査で、1文字ごとに比較します。これは参考実装であり、唯一の正解ではありません — 自分の実装と比較してみてください。