Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Welcome to GDB Online.
  4. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, HTML, CSS, JS.
  5. Code, Compile, Run and Debug online from anywhere in world.
  6.  
  7. *******************************************************************************/
  8. #include <stdio.h>
  9. #include <iostream>
  10. using namespace std;
  11.  
  12. #include<stdio.h>
  13.  
  14. int fib(int n)
  15. {
  16. /* Declare an array to store Fibonacci numbers. */
  17. int f[n+1];
  18. int i;
  19.  
  20. /* 0th and 1st number of the series are 0 and 1*/
  21. f[0] = 0;
  22. f[1] = 1;
  23.  
  24. for (i = 2; i <= n; i++)
  25. {
  26. /* Add the previous 2 numbers in the series
  27. and store it */
  28. f[i] = f[i-1] + f[i-2];
  29. }
  30.  
  31. return f[n];
  32. }
  33.  
  34. int main ()
  35. {
  36. int n = 7;
  37. printf("%d", fib(n));
  38. getchar();
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement