Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #iinclude <iostream>
- using std::cout;
- using std::cin;
- using std::endl;
- unsigned long fibonacci(unsigned long);
- int main()
- {
- unsigned long result, number;
- cout<<"Enter an integer\n";
- cin>>number;
- result=fibonacci(number);
- cout<<"Fibonacci number("<<number<<") = "<<result<<endl;
- return 0;
- }
- unsigned long fibonacci(unsigned long n)
- {
- if(n==0 || n==1)
- return n;
- else
- return fibonacci(n-1)+fibonacci(n-2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement