We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5a57907 commit 541829eCopy full SHA for 541829e
recursion/basic.go
@@ -10,14 +10,27 @@ func Basic(n int64) {
10
fmt.Println("Calculating fatorial for", n)
11
resp := fat(n)
12
fmt.Println("The response is", resp)
13
+ fmt.Println("Calculating fibonacci for", n)
14
+ resp = fib(n)
15
+ fmt.Println("The response is", resp)
16
}
17
-func fat(n int64) int64{
18
+func fat(n int64) int64 {
19
// stop condition
20
if n == 1 {
21
return 1
22
23
24
// calling itself again!
- return n * fat(n - 1)
25
+ return n * fat(n-1)
26
+}
27
+
28
+func fib(n int64) int64 {
29
+ // stop condition
30
+ if n > 1 {
31
+ // calling itself again!
32
+ return fib(n-1) + fib(n-2)
33
+ }
34
35
+ return 1
36
0 commit comments