编写斐波数列,输入n,输出数列中大于n的第一个数及其在数列中的位置感谢
#include<iostream>
using namespace std;
int main()
{
int f1, f2, t,i=1;
f1 = 0;
f2 = 1;
cout << "请输入t:";
cin >> t;
while(true)
{
f1+= f2;
i++;
if(f1>=t)
{
t=f1;
break;
}
f2+= f1;
i++;
if(f2>=t)
{
t=f2;
break;
}
}
cout<<"大于等于它的斐波那契数:"<<t<<"该数在斐波那契数列的项数是:"<<i<<endl;
system("pause");
return 0;
}