Advertisement
vaibhav1906

Recursive code for Fibonacci Number

Nov 24th, 2021
1,064
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.20 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int fib(int n) {
  4.         if(n<=1)
  5.             return n;
  6.         return fib(n-1)+fib(n-2);
  7.        
  8.     }
  9. };
  10. /*
  11. F(0)=0
  12. F(1)=1
  13. F(2)=1
  14. F(3)=2
  15. F(4)=3
  16. F(5)=5
  17. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement