SHARE
TWEET

C DP Fibonacci Serise

naeem043 Jul 13th, 2018 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top