返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.      for(int x=2 ; x <= 1000 ; x++){
  7.          int i=2 ;
  8.              while (x >= i ){
  9.                     if(x==i)
  10.                         {         
  11.                             cout<<x<<"是質數"<<endl;            
  12.                                 }               
  13.                                     else if((x%i)==0)
  14.                                         {
  15.                                             cout<<x<<"不是質數"<<endl;
  16.                                                 break;                    
  17.                                                     }
  18.                                                         i++;
  19.                                                             }
  20.                                                                 }
  21.                                                                      system("pause");
  22.                                                                          return 0;
  23.                                                                                 }
複製代碼

TOP

返回列表