forked from TheRealJishnu/Algorithm_sem_4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfibonacci.c
More file actions
42 lines (37 loc) · 637 Bytes
/
fibonacci.c
File metadata and controls
42 lines (37 loc) · 637 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
#include <stdio.h>
#include <stdlib.h>
int *arr;
int fibo(int n)
{
if(n == 1 || n == 0)
return n;
else
{
int a, b;
if(arr[n-1] == 0)
a = fibo(n-1);
else
a = arr[n-1];
if(arr[n-2] == 0)
b = fibo(n-2);
else
b = arr[n-2];
return a + b;
}
}
int main()
{
printf("Enter n : ");
int n;
scanf("%d", &n);
arr = (int*)calloc(n, sizeof(int));
for(int i=0; i<n; i++)
{
arr[i] = fibo(i);
}
for(int i=0; i<n; i++)
{
printf("%d\t", arr[i]);
}
printf("\n");
}