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

TOP

返回列表