39 lines
799 B
Go
39 lines
799 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"math"
|
|
)
|
|
|
|
func main() {
|
|
// prompt
|
|
fmt.Print("Enter 11 numbers: ")
|
|
// accept sequence
|
|
var s [11]float64
|
|
for i := 0; i < 11; {
|
|
if n, _ := fmt.Scan(&s[i]); n > 0 {
|
|
i++
|
|
}
|
|
}
|
|
// reverse sequence
|
|
for i, item := range s[:5] {
|
|
s[i], s[10-i] = s[10-i], item
|
|
}
|
|
// iterate
|
|
for _, item := range s {
|
|
if result, overflow := f(item); overflow {
|
|
// send alerts to stderr
|
|
log.Printf("f(%g) overflow", item)
|
|
} else {
|
|
// send normal results to stdout
|
|
fmt.Printf("f(%g) = %g\n", item, result)
|
|
}
|
|
}
|
|
}
|
|
|
|
func f(x float64) (float64, bool) {
|
|
result := math.Sqrt(math.Abs(x)) + 5*x*x*x
|
|
return result, result > 400
|
|
}
|