Skip to content

Commit 07d4935

Browse files
committed
Recursion
1 parent c8c18fd commit 07d4935

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Progress.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919
30
2020
31
2121
32
22-
33
22+
33
23+
34

factorialRecursion.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
double factorial(int n) {
5+
if (n == 0) {
6+
return 1;
7+
}
8+
return n * factorial(n - 1);
9+
}
10+
11+
int main() {
12+
cout << factorial(9);
13+
return 0;
14+
}

fibonacciRecursion.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int fibonacci(int n) {
5+
if (n == 0)
6+
return 0;
7+
if (n == 1)
8+
return 1;
9+
return fibonacci(n - 1) + fibonacci(n - 2);
10+
}
11+
12+
int main() {
13+
cout << fibonacci(5);
14+
return 0;
15+
}

0 commit comments

Comments
 (0)