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

TOP

返回列表