Sum Three Numbers
Given three integers, compute their sum and return the result. The sum is the total when all three numbers are added together.
For example, the sum of 2, 4, and 6 is 2 + 4 + 6 = 12. The sum of -5, 0, and 5 is 0. The sum of 100, 200, and 300 is 600. If all three numbers are zero, the sum is 0.
Adding numbers is the most fundamental arithmetic operation. This problem tests your ability to receive multiple inputs, perform addition, and return a result. The order of addition does not matter because addition is commutative and associative. You can add the first two numbers, then add the third to the total.
In pseudocode, this is as simple as writing the expression a + b + c. Most languages evaluate this left to right, computing (a + b) first, then adding c. The result is returned to the caller.
Edge cases include negative numbers (which correctly reduce the total), zero values (which do not affect the sum), and large numbers where the sum might exceed typical integer ranges. For the constraints of this problem, standard integer arithmetic is sufficient.
Example Input & Output
2 + 3 + 4 = 9.
-2 + 7 + 1 = 6.
10 + 0 + 5 = 15.
Algorithm Flow
Solution Approach
Add all three numbers together using the addition operator and return the result.
Compute a + b + c by using the + operator between each pair. The expression is evaluated left to right as (a + b) + c. The total is returned directly to the caller. No loops, conditions, or temporary variables beyond the implicit result are needed. This is the simplest possible function that performs arithmetic on multiple inputs.
Time complexity is O(1) since addition is a constant-time CPU operation regardless of the values being added. Space complexity is O(1).
Best Answers
program sum_three_numbers
dictionary
a, b, c, sum: integer
algorithm
input(a, b, c)
sum <- a + b + c
output(sum)
endprogramComments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
