Kodewick
开始学 →
入门←→0 / 70

读书月

#027入门数组循环约 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 也能运行
结果

写好了先点「运行」试试示例,没问题再点「提交」。