活動量計に毎日の歩数が記録されています。n 日分を合計する total_steps(steps, n) を書きましょう。ループはポインタ p を最初の日から最後の日まで動かします。p が指す値を total に足すだけです。n が 0 なら 0 を返します。
total_steps({3000, 4500, 5200}, 3)→12700total_steps({800}, 1)→800int total_steps(int *steps, int n)int total_steps(int *steps, int n) {
int total = 0;
for (int *p = steps; p < steps + n; p++) {
// ここにコードを書く:p が指す歩数を total に足す
}
return total;
}
実行すると例で試せます。よさそうなら提出しましょう。