-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab9b3.c
More file actions
50 lines (45 loc) · 943 Bytes
/
lab9b3.c
File metadata and controls
50 lines (45 loc) · 943 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
#include<stdio.h>
int daysof(int a);
int fibonacci(int n);
int main()
{
int a;//hien thi day so
printf("nhap so nguyen a: ");
scanf("%d",&a);
daysof(a);
int n;//hien thi vi tri
printf("\nnhap mot vi tri bat ky trong day: ");
scanf("%d",&n);
int result = fibonacci(n);
printf("so o vi tri thu %d la: %d \n",n, result);
return 0;
}
int daysof(int a)
{
int st =0;
int nd = 1;
int next;
printf("Day gom %d so fibonacci day tien la: ", a);
for(int i =0; i <= a; i++)
{
printf("%d ", st);
next = st + nd;
st =nd;
nd =next;
}
}
int fibonacci(int n)
{
if(n<=0)
{
return 0;
}
else if(n == 1)
{
return 1;
}
else
{
return fibonacci(n-1) + fibonacci(n - 2);
}
}