小弟是用c++
程式碼如下 在電腦上顯示ok
船上來卻顯示ce
#include <iostream>
using namespace std;
int main()
{
unsigned long Num,Num2,bh;
char a;
bool temp;
again:
cin >> Num;
Num2 = Num / 2;
temp = true;
for (unsigned long i = 2;i <= Num2;i++)
{
if (Num % i == 0)
{
temp = false;
goto exit;
}
}
exit:
if (temp == false)
cout << "\非質數。\n";
else
cout << "\質數。\n";
system("pause");
return 0;
}
小弟是用c++
程式碼如下 在電腦上顯示ok
船上來卻顯示ce
#include
using namespace std;
int main()
{
unsigned long Num,Num2,bh;
char a;
bool temp;
again:
cin >> Num;//要反覆執行的話用WHILE
Num2 = Num / 2;//應該改成Num的二分之一"次方",不然會逾時
temp = true;
for (unsigned long i = 2;i <= Num2;i++)
{
if (Num % i == 0)
{
temp = false;
goto exit;//建議不要用GOTO 這邊用BREAK就可以了 }
}
exit:
if (temp == false)
cout << "\非質數。\n";
else
cout << "\質數。\n";
system("pause");
return 0;
}