Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Solution written in Go for challenge 2012-03-16 on ProgrammingPraxis.com
package main
import (
"fmt"
"math"
)
func main() {
fmt.Println("Exercise from: http://programmingpraxis.com/2012/03/16/sum-of-squares-of-two-largest-of-three-values/")
fmt.Println("Exercise: Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.")
fmt.Println("sum_of_squares_of_largest_two_numbers(2, 3, 1):", sum_of_squares_of_largest_two_numbers(2, 3, 1))
}
func sum_of_squares_of_largest_two_numbers(a, b, c float64) float64 {
return math.Pow(math.Max(a, b), 2) + math.Pow(math.Max(math.Min(a, b), c), 2)
}
@ChristianSiegert

Console output:

$ go run challenge-2012-03-16.go 
Exercise from: http://programmingpraxis.com/2012/03/16/sum-of-squares-of-two-largest-of-three-values/
Exercise: Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers.
sum_of_squares_of_largest_two_numbers(2, 3, 1): 13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.