• C++ ~很難我不會

    Posted on 二月 6th, 2010 天使.路西法 1 comment

    撰寫一個程式,並列出m~n之間的質數。其中m及n由使用者輸入。
    可以用指數的話就用指數~
    謝謝><

     

    1 responses to “C++ ~很難我不會” RSS icon

    • 不想安靜 畫不完="=

      #include <iostream>
      using namespace std;

      int main(){
       int n=0, m=0, i=0, j=0;

       cout<<"Please input m: ";
       cin>>m;
       cout<<"Please input n: ";
       cin>>n;

       for (i = m; i <= n; i++)
       {
        for (j = 2; j < i; j++)
         if (i % j == 0)
          break;
        if (i == j)
         cout<<"  "<<i;
       }
       cout<<endl;

      return 0;
      }


    Leave a reply

    抱歉,您必須要登入才能發表迴響喔!