Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,38 @@
|
|||
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
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
func f(t float64) float64 {
|
||||
return math.Sqrt(math.Abs(t)) + 5*math.Pow(t, 3)
|
||||
}
|
||||
|
||||
func main() {
|
||||
var a [11]float64
|
||||
for i := range a {
|
||||
fmt.Scan(&a[i])
|
||||
}
|
||||
for i := len(a) - 1; i >= 0; i-- {
|
||||
if y := f(a[i]); y > 400 {
|
||||
fmt.Println(i, "TOO LARGE")
|
||||
} else {
|
||||
fmt.Println(i, y)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue