#include <iostream>
using namespace std;
int main()
{int fun(int x);
int n,a;
cout<<"please enter n:";
cin>>n;
if(n>0&&n<2) a=1;
else a=fun(n);
cout<<"Fib="<<a<<endl;
return 0;
}
int fun(int x)
{
int i=1,sum,q=0,p=1;
while (i<=x-1)
{sum=q+p;
q=p;
p=sum;
i++;
}
return(sum);
}
网友评论