【发布时间】:2019-03-23 12:25:06
【问题描述】:
我的程序无法显示斐波那契数列,但我认为代码是正确的,有人知道为什么吗?
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
using namespace std;
int main()
{
int a=0,b=1,c;
cout << "Fibonacci number" << endl;
cout << a << " ";
cout << b << " ";
while (c<100)
{
c=a+b;
a=b;
b=c;
}
cout << c << " ";
return 0;
}
【问题讨论】:
-
听起来您可能需要学习如何使用调试器来单步调试您的代码。使用好的调试器,您可以逐行执行您的程序,并查看它与您期望的偏差在哪里。如果您要进行任何编程,这是必不可少的工具。延伸阅读:How to debug small programs
-
c从未初始化。 -
如果你想打印每个词,打印语句不应该是你计算每个词的地方吗?
-
@NeilButterworth C 不应该初始化
-
@alifarokhi no
c需要为while (c<100)初始化
标签: c++ while-loop logic fibonacci