basics · beginner · ~15 min
Iterate over an array with a size parameter.
Implement long sum_array(const int *a, size_t n) returning the sum of the first n ints in a. n may be zero.
#include <stddef.h>
long sum_array(const int *a, size_t n) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.