230k views
3 votes
Given 2 ints, a and b, return their sum. However, sums in the range 10..19 inclusive, are forbidden, so in that case just return 20.

A sortaSum(3, 4) → 7
B sortaSum(9, 4) → 20
C sortaSum(10, 11) → 21

1 Answer

5 votes

Final answer:

The function in question adds two integers and returns the sum unless the sum is between 10 and 19, in which case it returns 20. For the given examples, we apply this rule and get 7, 20, and 21 for sortaSum(3, 4), sortaSum(9, 4), and sortaSum(10, 11) respectively.

Step-by-step explanation:

The question presented involves a function that outputs the sum of two integers, a and b. However, the function has a special condition: if the sum of a and b is within the range of 10 to 19 inclusive, the function returns 20 instead of the actual sum. Otherwise, it just returns the sum of the two numbers.

To solve each part, we simply apply the given rule:

  • A sortaSum(3, 4) → Since 3 + 4 equals 7, which is not in the 10-19 range, the function returns 7.
  • B sortaSum(9, 4) → Since 9 + 4 equals 13, which is in the 10-19 range, the function returns 20.
  • C sortaSum(10, 11) → Since 10 + 11 equals 21, which is not in the 10-19 range, the function returns 21.

This demonstrates an exercise in conditional logic often found in programming and algorithm design, despite being framed as a mathematics question.

User Prichmp
by
8.2k points