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

  26.    system("pause");
  27.    return 0;
  28. }
複製代碼

TOP

返回列表