原始碼:http://down.gogobox.com.tw/t2329175/jw2m2
//從簡單的開始吧!
/*
Name: 質因數判斷
Date: 19/06/08 09:59
*/
#include
int main()
{
using namespace std;
unsigned long Num,Num2,bh;
char a;
bool temp;
again:
cout << "請輸入一個正整數:__________\b\b\b\b\b\b\b\b\b\b";
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不是質數。\n";
else
cout << "\n是質數。\n";
cout << "是否繼續?(y/n)";
cin.get();
a = getchar();
system("cls");
if (a == 'y')
goto again;
else
system("pause");
return 0;
}
公告版位
星落的瞬間!放棄的後悔是永遠!
- Jun 19 Thu 2008 10:26
判斷質數(C++)
全站熱搜
留言列表
發表留言