Fibonacci Sequence in Go
package main import "fmt" // Fibonacci Sequence is 0 1 1 2 3 5 8 13 21 ....... // Read more on // https://www.mathsisfun.com/numbers/fibonacci-sequence.html#:~:text=It%20is%20that%20simple!,out%20the%20next%20few%20numbers%3F func main() { n := 10 a := 0 b := 1 c := 0 for i := 1 ; i <= n; i ++ { fmt.Printf( "%d " , a) c = a + b a = b b = c } } /* Logic explaination Algorithm Add 'a + b', Store into 'c' Swap current 'b's value into 'a' Swap current 'c's value into 'b' print 'a' while N th term Initially a = 0, b = 1 , c = 0 First interation fmt.Printf("%d ", a) : 0 Second itertaion a = 0 b = 1 c = a + b , c = 1 a = b , a = 1 b = c , b = 1 fmt.Printf("%d ", a): 0 1 Third iteration a = 1 b = 1 c = a + b , c = 2 a = b , a = 1 b = c , b = 2 fmt.Printf("%d ", a): 0 1 1 ...