/*
Recursive Fibonacci
*/
#include <iostream>
using namespace std;
int fib(int n)
{
int f0=0, f1=1;
int num;
if (n<2)
return n;
else
{
return fib(n-1)+fib(n-2);
}
}
int main()
{
int n;
cout << "pls enter n: ";
cin >> n;
if (!cin.good())
{
cout << "incorrect input!\n";
return(2);
}
cout << fib(n) << endl;
return 0;
}
Recursive Fibonacci
最新推荐文章于 2023-05-08 16:45:30 发布