当我运行这个程序(我使用的代码块和它的全面升级),它显示一个对话框: “”“” .EXE已停止工作 问题导致程序无法正常工作。 Windows将关闭该程序并通知如果解决方案是可用的。“”“”.exe文件停止工作,当我运行一个C++程序(没有“/ 0”)
#include <iostream>
#include <math.h>
#include <conio.h>
using namespace std;
int main()
{
int no, hlf, arr[no], arrno;
cout << "ENTER A NUMBER";
cin >> no;
hlf = ceil(no/2);
for(int i = 1;i <= no;i++)
{
for(int j = 2;j <= hlf;j++)
{
int ij = i/j;
if(j != i && ij == 0)
{
goto cont;
}
else
{
continue;
}
}
arr[arrno] = i;
arrno++;
cont: ;
}
for(int k = 0;k <= arrno;k++)
{
cout << arr[k] << " ";
}
getch();
return 0;
}
这意味着你的程序崩溃*。你应该使用一个*调试器*来找出在哪里,并帮助你找出原因。也许你也应该阅读埃里克利珀[如何调试小程序(https://ericlippert.com/2014/03/05/how-to-debug-small-programs/)。 –
我建议你记下所有的变量及其值,然后在代码更新时更新代码。你会很快发现你的代码存在问题。 –
尽管如此:在没有循环的情况下,程序执行从上到下。你的程序不会回头去做一些事情,比如追溯重新定义变量。在初始化之前使用'no'时,请考虑这一点。 –