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

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6. int b=0;
  7. cout<<"10000以內的質數有:"<<endl;     
  8. for(int i=2; i<=10000;i++)   
  9. {   
  10.     int x=0;  
  11.     for(int j=2; j<=i;j++)
  12.   {
  13.      if(i%j==0)
  14.     {
  15.      x++;
  16.     }
  17.   }  
  18.     if(x==1)
  19.     {
  20.      b++;
  21.      cout<< i <<endl;
  22.     }
  23. }  
  24.     cout<<"共有"<<b<<"個質數"<<endl;
  25.     system("pause");
  26.     return 0;     
  27. }
複製代碼

TOP

返回列表