Advertisement
naeem043

C DP Fibonacci Serise

Jul 13th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1.  
  2. #include<stdio.h>
  3.  
  4. int f[100];
  5.  
  6. int fibo(int n)
  7. {
  8.     if(n==0) return f[0];
  9.     if(n==1) return f[1];
  10.     if(f[n]!= 0) return f[n];
  11.  
  12.  
  13.     return f[n] = fibo(n-1) + fibo(n-2);
  14.  
  15. }
  16. int main()
  17. {
  18.     int n,x,i;
  19.     f[0] = 0;
  20.     f[1] = 1;
  21.  
  22.     scanf("%d",&n,printf("Enter the value of n:\t"));
  23.     x = fibo(n);
  24.  
  25.     printf("%d\n",x);
  26.     for(i=0;i<100;i++)
  27.         printf("%d\t",f[i]);
  28.  
  29.     printf("%d\n",x);
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement