Kodewick
学びはじめる →
入門←→0 / 70

読書月間

#027入門total += books[i]約 3 分

読書月間が終わりました。クラスメート n 人が読んだ本の数が配列 books に入っています。クラス全体で読んだ冊数を返す total_books(books, n) を書きましょう。だれもいない(n が 0)なら 0 です。

例
total_books({3, 5, 2}, 3)→10
total_books({}, 0)→0
関数int total_books(int books[], int n)
main.c
int total_books(int books[], int n) {
    int total = 0;
    for (int i = 0; i < n; i++) {
        // ここにコードを書く:i 番目の人の冊数を total に足す
    }
    return total;
}
Ctrl + Enter でも実行できます
結果

実行すると例で試せます。よさそうなら提出しましょう。