basics · beginner · ~15 min

Sum a range

Write a small unit a build would compile and link.

Challenge

Implement long sum_range(int lo, int hi) returning the sum of all integers from lo to hi inclusive. If lo > hi, return 0.

Starter code

long sum_range(int lo, int hi) {
    /* TODO */
    return 0;
}

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