-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLecture31.cpp
More file actions
68 lines (44 loc) · 1.11 KB
/
Copy pathLecture31.cpp
File metadata and controls
68 lines (44 loc) · 1.11 KB
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
62
63
64
65
66
67
68
#include<iostream>
using namespace std;
// head recursion
void print(int n) {
//base case
if(n == 0)
return ;
print(n-1); //recursive relation
cout << n << endl; // processing
}
// tail recursion
void print(int n) {
//base case
if(n == 0)
return ;
cout << n << endl; // processing
print(n-1); //recursive relation
}
int power(int n) {
//base case
if(n == 0)
return 1;
//recursive relation
int smallerProblem = power(n-1);
int biggerProblem = 3 * smallerProblem;
return biggerProblem;
}
int factorial(int n) {
//base case :
if(n==0)
return 1;
//recursive relation :
int smallerProblem = factorial(n-1);
int biggerProblem = n * smallerProblem;
return biggerProblem;
}
int main() {
int n;
cin >> n;
// int ans = factorial(n);
// int ans = power(n);
// cout << ans << endl;
print(n);
}