-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1029.cpp
More file actions
76 lines (66 loc) · 878 Bytes
/
1029.cpp
File metadata and controls
76 lines (66 loc) · 878 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
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
#include <iostream>
#include <cstdio>
int num;
using namespace std;
int fib(int m){
num++;
if(m==0)
return 0;
else{
if(m==1)
return 1;
else
return fib(m-1)+fib(m-2);
}
}
int main(){
int n,m,a,i;
scanf("%d",&n);
while(n){
scanf("%d",&m);
num=-1;
a=fib(m);
printf("fib(%d) = %d calls = %d\n",m,num,a);
n--;
num=0;
}
return 0;
}
/* FIbbonaci COM PD
#include <iostream>
#include <cstdio>
int num;
using namespace std;
int fib(int m, int vet[]){
int j;
num++;
if(vet[m])
return vet[m];
else{
if(m==0)
j=0;
else{
if(m==1)
j=1;
else
j=(fib(m-1,vet)+fib(m-2,vet));
}
}
return j;
}
int main(){
int n,m,a,i,vet[40];
scanf("%d",&n);
while(n){
scanf("%d",&m);
for(i=1;i<=m;i++)
vet[i]=0;
num=-1;
a=fib(m,vet);
printf("fib(%d) = %d calls = %d\n",m,num,a);
n--;
num=0;
}
return 0;
}
*/