-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLecture32.cpp
More file actions
99 lines (69 loc) · 1.63 KB
/
Copy pathLecture32.cpp
File metadata and controls
99 lines (69 loc) · 1.63 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include<iostream>
using namespace std;
void reachHome(int src, int dest) {
cout << "source at " << src << " destination is " << dest << endl;
//base case
if(src == dest) {
cout << "source has been reached to the destination. " << endl;
return ;
}
//processing - ek step aage badhjao
src++;
//recursive call
reachHome(src, dest);
}
void sayDigit(int n, string arr[]) {
//base case
if(n == 0)
return ;
//processing
int digit = n % 10;
n = n / 10;
//recursive call
sayDigit(n, arr);
cout << arr[digit] << " ";
}
int countDistinctWayToClimbStair(long long nStairs)
{
//base case
if(nStairs < 0)
return 0;
if(nStairs == 0)
return 1;
//R.C
int ans1 = (countDistinctWayToClimbStair(nStairs-1) + countDistinctWayToClimbStair(nStairs-2));
return ans1;
}
int fib(int n) {
// base case
if(n==0){
return 0;
}
else if(n==1){
return 1;
}
// recursice relation
else{
int ans2 = (fib(n-1) + fib(n-2));
return ans2;
}
}
int main() {
int dest = 10;
int src = 1;
cout << endl;
reachHome(src, dest);
// int p;
// cin>>p;
// int answer1 = fib(p);
// cout << answer1 << endl;
// int answer2 = countDistinctWayToClimbStair(p);
// cout << answer2 << endl;
string arr[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
int n;
cin >> n;
cout << endl << endl << endl ;
sayDigit(n, arr);
cout << endl << endl << endl ;
return 0;
}