#include <iostream>
using namespace std;
int main()
{
int a=1,b=1;
cout << a << " " ;
while (b<100&&a<100)
{
a=a+b;
cout << b << " ";
cout << a << " " ;
b=b+a;
}
return 0;
}
本文通过一个简单的C++程序展示了如何打印斐波那契数列。程序使用了两个变量交替更新的方法来生成数列,并在每一步迭代中输出当前的数列值。这种方法直观且易于理解。
#include <iostream>
using namespace std;
int main()
{
int a=1,b=1;
cout << a << " " ;
while (b<100&&a<100)
{
a=a+b;
cout << b << " ";
cout << a << " " ;
b=b+a;
}
return 0;
}

被折叠的 条评论
为什么被折叠?