basics · beginner · ~15 min
Combine several variables in an expression.
Add three integers, returning a wide enough type to avoid overflow.
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.
Three ints a, b, and c.
Returns their sum, as a long.
sum3(1, 2, 3) -> 6
sum3(-5, 5, 0) -> 0
Three ints a, b, and c.
Their sum, as a long.
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.