當我運行這個程序(我使用的代碼塊和它的全面升級),它顯示一個對話框: 「」「」 .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'時,請考慮這一點。 –