-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathFibbonacci.cpp
More file actions
43 lines (39 loc) · 795 Bytes
/
Fibbonacci.cpp
File metadata and controls
43 lines (39 loc) · 795 Bytes
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
#include <iostream>
using namespace std;
int recursive_func(int n);
int func(int n);
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
for (int i = 0; i <= n; i++)
cout << func(i) << " ";
cout << endl;
for (int i = 0; i <= n; i++)
cout << recursive_func(i) << " ";
return 0;
}
int recursive_func(int n)
{
if (n == 0 || n == 1)
{
return n;
}
return recursive_func(n - 1) + recursive_func(n - 2);
}
int func(int n)
{
int first = 0;
int second = 1;
for (int i = 0; i < n; i++)
{
int temp = first;
first = second;
second = temp + second;
}
return first;
}