basics · beginner · ~15 min

Product of a range

Reuse the loop pattern for a product.

Challenge

Implement long product_range(int lo, int hi) returning the product of integers lo..hi inclusive. If lo > hi, return 1 (the empty product).

Starter code

long product_range(int lo, int hi) {
    /* TODO */
    return 1;
}

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