-
Notifications
You must be signed in to change notification settings - Fork 0
/
fib.cpp
67 lines (58 loc) · 926 Bytes
/
fib.cpp
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
#include <iostream>
using namespace std;
int fib(int x)
{
// base case
if(x<2)
{
return x;
}
return fib(x-1)+fib(x-2);
}
int rev(int n)
{
int rev = 0;
while(n!=0)
{
int x = n%10;
rev = rev*10 + x;
n = n/10;
}
return rev;
}
void sayDigits(int n, string arr[], int k)
{
// base case
if(n == 0)
{
return ;
}
int last = n%10;
n = n/10;
sayDigits(n,arr,k);
cout<<arr[last]<<" ";
}
int climb(int n)
{
if(n<0)
{
return 0;
}
if(n == 0)
{
return 1;
}
return climb(n-1) + climb(n-2);
}
int main(){
int n;
cin>>n;
// int x = rev(n);
//cout<<x<<endl;
int k = 10;
string arr[k] = {"zero","one", "two", "three","four","five","six","seven", "eight","nine"};
//sayDigits(n,arr,k);
// cout<<fib(n)<<endl;
cout<<climb(n)<<endl;
return 0;
}