返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.    cout<<"***天才兒童的質數驗證器***"<<endl;
  7.    re:
  8.    int x,y=0;
  9.       cout<<"請輸入一個正整數:";
  10.       cin>>x;
  11.       for(int i=1;i<=x;i++)
  12.       {
  13.           if(x%i==0)
  14.           {
  15.               y++;
  16.           }
  17.       }
  18.       if(y==2)
  19.       {
  20.           cout<<x<<"是質數"<<endl;
  21.       }
  22.       else
  23.       {
  24.           cout<<x<<"非質數"<<endl;
  25.       }
  26.    goto re;
  27.    system("pause");
  28.    return 0;
  29. }
複製代碼

TOP

返回列表