讀書月結束了,n 個同學每人讀的本數在陣列 books 裡。寫 total_books(books, n),返回全班一共讀了幾本。沒有人(n 是 0)就是 0。
total_books({3, 5, 2}, 3)→10total_books({}, 0)→0int total_books(int books[], int n)int total_books(int books[], int n) {
int total = 0;
for (int i = 0; i < n; i++) {
// 在這裡寫:把第 i 個同學讀的本數加到 total 上
}
return total;
}
寫好了先點「執行」試試示例,沒問題再點「提交」。