2018年11月29日 星期四

1129C++

 c/c++研習資料夾

#include <iostream>
using namespace std;
int p[ 100 ];
int pcnt;
bool isp(int x)
{
     int i;
 //    cout << "試" << x;
     if(x<2) return false;
     for (i=2; i*i<=x; i++)
     {// cout  <<"%" << i << ',';
       if (x%i==0) return false;
     }
    // cout << "是\n" ;
     return true;
}
int main()
{
  int n, i,j;
  cin >> n;
  pcnt =0;
  for (i=1 ; i<=n; ++i)
  {
        if( isp( i ) )
        {
           p[pcnt] = i; // i=1 
           pcnt ++;
           //cout << pcnt <<":"<<p[pcnt-1] << " ";
        }
  }
  // 共 pcnt , p[0] ~ p[cnt-1]
  cout << pcnt <<"," << p[pcnt-1] << endl;
  system("pause");
  return 0;
}

Related Posts:

  • 北二區101-5滾球遊戲(zj:a822改) 改版後範例輸入 2 3 1 1 4 0 0 範例輸出 1 9 5 5… Read More
  • b515 摩斯電碼 /*  b515 2014 高職 商業技藝競賽 模擬 P21 摩斯電碼 A .- B -... C -.-. D -..  E . F ..-. G --. H .... I .. J .--- K -.- L .-..  M -- N -. O --- P .… Read More
  • 滾球遊戲(C++參考版) 參考程式碼: #include <iostream> #include <cstring> using namespace std; const int MaxN = 500; int gb[MaxN][MaxN];  // 遊戲盤數值 int b… Read More
  • 找零使用最少硬幣數 設有5種硬幣:1, 5, 6, 7, 15:找零50元使用最少數量的硬幣 先設定1~50中只需要1個及2個硬幣的數額;1個:1, 5, 6, 7, 15 2個:2{1+1},8{1+7},16{1+15},10{5+5},11{5+6}… Read More
  • 北二區101-3小精靈吃數字/* a820-y6m8 北二區101年第3題:小精靈吃數字 第一列 X格,Y列(沒明確說明,假設10x10),第二列至第(Y+1)列皆有(X)個數{且-9<=*<=9},第(Y+2)列為起點(SX,SY)及方向1右上2左上3左下4右下  反彈三次後,即第4次不反彈離開,問經過… Read More

0 意見:

張貼留言