Largest sum
Lesson 18 of 32 in Coddy's Coding Problems course.
Challenge
MediumYour teacher wrote three positive numbers on the board A, B, C. Then, your teacher gives you a challenge: Pick one of the three numbers and replace it with its square (X2), so that when you sum the three numbers after the replacement you get the largest sum possible.
Write a function named sum that given three natural numbers A, B, C from input. Return the largest sum possible with replacing one number with its square.
Input
1 5 5
Output
31
Input
0 1 10
Output
101
Explanation #1: We replace one of the 5s with its square - 25, so we get 1 + 5 + 25 = 31
Explanation #2: We replace the 10 with its square - 100, we get 0 + 1 + 100 = 101
Try it yourself
int sum(int a1, int a2, int a3) {
// Write code here
}All lessons in Coding Problems
1Course Introduction
Introduction3Medium Difficulty
Candy BarsFibonacci NumbersFactorialNumber of digitsLeast common multipleLargest sumNotebookApplesGiftsDog yearsAnagrams