Guest User

Untitled

a guest
Mar 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.25 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "fmt"
  5. )
  6.  
  7. func fibonacci(n int, c chan int) {
  8. x, y := 0, 1
  9. for i := 0; i < n; i++ {
  10. c <- x
  11. x, y = y, x+y
  12. }
  13. close(c)
  14. }
  15.  
  16. func main() {
  17. c := make(chan int, 10)
  18. go fibonacci(cap(c), c)
  19. for i := range c {
  20. fmt.Println(i)
  21. }
  22. }
Add Comment
Please, Sign In to add comment