#include<iostream>
using namespace std;
int fib(int n);
int main(){
int i, n;
cout<<"请输入fibnacci数列的项数:";
cin>>n;
for(i=1;i<=n;i++)
{
cout<<fib(i)<<" ";
}
cout<<endl;
return 0;
}
int fib(int n)
{
int sum=0;
if(n==1)
sum=0;
else if(n==2)
sum=1;
else sum=fib(n-1)+fib(n-2);
return sum;
}
菲比列数列
最新推荐文章于 2022-12-07 15:45:27 发布