basics · beginner · ~15 min

Sum of three

Combine several variables in an expression.

Challenge

Add three integers, returning a wide enough type to avoid overflow.

Task

Implement long sum3(int a, int b, int c) that returns a + b + c as a long. Promote to long before adding so large inputs don't overflow. No main — the grader calls it.

Input

Three ints a, b, and c.

Output

Returns their sum, as a long.

Example

sum3(1, 2, 3)     ->   6
sum3(-5, 5, 0)    ->   0

Edge cases

  • Mixed positive and negative inputs sum normally.

Input format

Three ints a, b, and c.

Output format

Their sum, as a long.

Starter code

long sum3(int a, int b, int c) {
    /* TODO */
    return 0;
}

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