Tech Tips

  1. Uncategorized
  2. 117 view

[Go]Output Fibonacci Series

Output Fibonaaci Series with Go.
package main

var ch = make(chan int)
var array [10]int

func fib(init int) {
    switch {
        case init == 0 || init == 1 :
            array[init] = 1
            ch <- array[init];
            return
        case init >= 2 :
            array[init] = array[init-2] + array[init-1]
            ch <- array[init]
            return
    }
}

func main() {
    for i := 0; i <= 0; i++ {
        array[i] = 0
    }

    for num := 0; num < 10; num++ {
        go fib(num);
        println(<- ch);
    }
}
Run.
$pwd
-> $GOPATH
$go install example/fib
$fib/fib
1
1
2
3
5
8
13
21
34
55

Uncategorized recent post

  1. Run Amazon FreeRTOS on M5Stack Core2 for AWS …

  2. Udacity Self-Driving Car Engineer Nanodegree …

  3. Install sbt 1.0.0 and run sample template

  4. Visualization of Neural Network and its Train…

  5. [Machine Learning]Created docker image includ…

関連記事

PAGE TOP