原始碼: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;
}



arrow
arrow
    全站熱搜

    讓地獄深紅的天亮 發表在 痞客邦 留言(0) 人氣()