mhdew

Fibonacci using recursion

Dec 22nd, 2017
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int fib(int i)
  4. {
  5. if(i==0 || i==1){
  6. return i;
  7. }
  8. else{
  9. return fib(i-1)+fib(i-2);
  10. }
  11. }
  12.  
  13. int main()
  14. {
  15. int i=0, n, j;
  16.  
  17. scanf("%d", &n);
  18.  
  19. for(j=1;j<=n;j++){
  20. printf("%d ", fib(i));
  21. i++;
  22. }
  23. return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment