Kodewick
Start learning →
Basic←→0 / 70

Steps this week

#052BasicPointersArrays4 min

The fitness band saved each day's steps. Write total_steps(steps, n) to add up n days. The loop moves a pointer p from the first day to the last; you just add what p points to into total. When n is 0 it gives 0.

Examples
total_steps({3000, 4500, 5200}, 3)→12700
total_steps({800}, 1)→800
The functionint total_steps(int *steps, int n)
main.c
int total_steps(int *steps, int n) {
    int total = 0;
    for (int *p = steps; p < steps + n; p++) {
        // your code here: add the steps p points to into total
    }
    return total;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.