fork download
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. "math"
  6. )
  7.  
  8. func main() {
  9. fmt.Println(pi(5000))
  10. }
  11.  
  12. func pi(n int) float64 {
  13. ch := make(chan float64)
  14. for k := 0; k <= n; k++ {
  15. go term(ch, float64(k))
  16. }
  17. f := 0.0
  18. for k := 0; k <= n; k++ {
  19. f += <-ch
  20. }
  21. return f
  22. }
  23.  
  24. func term(ch chan float64, k float64) {
  25. ch <- 4 * math.Pow(-1, k) / (2*k + 1)
  26. }
  27.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.go:19: invalid operation: f += <-ch (type float + float64)
prog.go:21: cannot use f (type float) as type float64 in return argument
stdout
Standard output is empty