斐波那契序列生成器
Fibonacci Sequence Generator in C++
我正试图在c++中制作斐波那契序列生成器,并且遇到了一些麻烦。我是c++的新手,并试图使它像我在我所知道的其他语言中所做的那样工作。所以我写了一个程序:
#include <iostream>
using namespace std;
int NextNumber(int x, int y, int z)
{
z=x+y;
return z;
}
int main()
{
int q;
int w;
int x=0;
int y=1;
int z=1;
int t=1;
cout << x;
cout << ", "<< y ;
cout << ", "<< z ;
while (t<10)
x=NextNumber(y,z,x);
cout << ", "<< x ;
q=y; //Q is farthest back
w=z; //W is in the middle
z=x; //Z moves from middle to front
y=w; //Y moves from back to middle
x=q; //X moves from front to back
t=t+1; //Add a rotation to the while loop
}
我使用Xcode来编译,当我运行程序时,似乎没有显示输出。如果有人有任何想法,为什么这可能会发生,或者如果我的程序有任何逻辑缺陷,请帮助。谢谢你。
c++不是Python,并且空格被编译器忽略。必须对while
循环使用大括号
while (t<10)
{
// details
} // end loop
相关文章:
- 没有找到相关文章