forked from unknwon/the-way-to-go_ZH_CN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_fibo.go
executable file
·61 lines (55 loc) · 937 Bytes
/
main_fibo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"./fibo/fibo"
"fmt"
)
var nextFibo int
var op string
func main() {
/*
result := 0
for i:=0; i <= 10; i++ {
result = fibo.Fibonacci(i)
fmt.Printf("fibonacci(%d) is: %d\n", i, result)
}
*/
op = "+"
calls()
fmt.Println("Change of operation from + to *")
nextFibo = 0
op = "*"
calls()
}
func calls() {
next()
fmt.Println("...")
next()
fmt.Println("...")
next()
fmt.Println("...")
next()
}
func next() {
result := 0
nextFibo++
result = fibo.Fibonacci(op, nextFibo)
fmt.Printf("fibonacci(%d) is: %d\n", nextFibo, result)
}
/* *****************************************************************
Output is:
fibonacci(1) is: 1
...
fibonacci(2) is: 2
...
fibonacci(3) is: 3
...
fibonacci(4) is: 5
Change of operation from + to *
fibonacci(1) is: 2
...
fibonacci(2) is: 4
...
fibonacci(3) is: 8
...
fibonacci(4) is: 32
********************************************************************/