using namespace std;
int fibonacci(int x);
int main()
{
int n;
cout<<"需要计算的fibonacci数列:";
while(cin>>n)
{
cout<<"fibonacci = "<<fibonacci(n)<<endl;
cout<<"需要计算的fibonacci数列:";
}
return 0;
}
int fibonacci(int x)
{
if(x<=1)
return 1;
else{return fibonacci(x-1)+fibonacci(x-2);}
}
程序运行结果: