Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> //exercise 4
- #include <algorithm>//create a recursive function that computes n-Fibonacci number
- using namespace std;
- int fib(int n)
- {
- if (n < 2)
- return n;
- else
- return fib(n - 1) + fib(n - 2);
- }
- int main()
- {
- int n;
- cout << "Which Fibonacci number do you want to know? ";
- cin >> n;
- cout << "Your Fibonacci number is " << fib(n) << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement