Advertisement
gasaichan

Fibonacci search

May 17th, 2018
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #iinclude <iostream>
  2.  
  3. using std::cout;
  4. using std::cin;
  5. using std::endl;
  6.  
  7. unsigned long fibonacci(unsigned long);
  8.  
  9. int main()
  10. {
  11.     unsigned long result, number;
  12.     cout<<"Enter an integer\n";
  13.     cin>>number;
  14.    
  15.     result=fibonacci(number);
  16.    
  17.     cout<<"Fibonacci number("<<number<<") = "<<result<<endl;
  18.     return 0;
  19. }
  20.  
  21. unsigned long fibonacci(unsigned long n)
  22. {
  23.     if(n==0 || n==1)
  24.         return n;
  25.     else
  26.         return fibonacci(n-1)+fibonacci(n-2);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement