basics · beginner · ~15 min

Sum an array

Iterate an array by index.

Challenge

Implement long array_sum(const int *a, int n) returning the sum of the first n elements.

Starter code

long array_sum(const int *a, int n) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.