Created
July 2, 2020 17:26
-
-
Save otilor/1d9d2a60927e8d018544f3c95030cd06 to your computer and use it in GitHub Desktop.
Hennge challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
var sum float64 | |
func main() { | |
fmt.Println("Boring Hennge challenge.") | |
var numberOfTestCases int | |
_, _ = fmt.Scanf("%d", &numberOfTestCases) | |
startMainApplication(numberOfTestCases) | |
} | |
func startMainApplication(numberOfTestCases int) { | |
if numberOfTestCases < 1 { | |
return | |
} | |
var numberOfSpaceSeparatedIntegers int | |
_, _ = fmt.Scanf("%d", &numberOfSpaceSeparatedIntegers) | |
takeInNumbers(numberOfSpaceSeparatedIntegers) | |
fmt.Println(sum) | |
sum = 0 | |
numberOfTestCases-- | |
startMainApplication(numberOfTestCases) | |
// | |
} | |
func takeInNumbers(numberOf int) { | |
if numberOf < 1 { | |
return | |
} | |
var number int | |
_, _ = fmt.Scanf("%d", &number) | |
if !isNegative(number) { | |
sum += math.Pow(float64(number), 2.0) | |
} | |
numberOf-- | |
takeInNumbers(numberOf) | |
} | |
func isNegative(number int) bool { | |
if number < 0 { | |
return true | |
} | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment