Advertisement
mhdew

Fibonacci without DP

Dec 9th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.24 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. long long fib(int n)
  6. {
  7.     if(n==0 || n==1) return n;
  8.     else return fib(n-1)+fib(n-2);
  9. }
  10.  
  11. int main()
  12. {
  13.     int n;
  14.     scanf("%d", &n);
  15.     printf("%lld", fib(n));
  16.  
  17.     return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement