Re: [請益] 誰會c++阿>.<

看板Ju-88作者 (Joybo)時間20年前 (2004/04/20 02:00), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串11/11 (看更多)
※ 引述《elve (努力..)》之銘言: : 下面是完整的程式了 我跑過也改過了 你看看吧... : 有不懂的地方在問我~ 43,那我來個C++的方法 #include <iostream.h> #include <math.h> bool isPrime(int n){ for(int i=2;i<=sqrt(n);i++) if(n%i==0) return false; return true; } int main(){ int m,n; int c=0; cout<<"please enter two numbers: "; cin>>m>>n; if(m>n) m^=n^=m^=n; //m一定小於n for(int i=m;i<=n;i++) if(isPrime(i)) c++; cout<<"there are "<<c<<" primes"<<endl; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.216.141.17 ※ 編輯: Joybo 來自: 61.216.141.17 (04/19 18:02)
文章代碼(AID): #10X1E-vk (Ju-88)
討論串 (同標題文章)
文章代碼(AID): #10X1E-vk (Ju-88)