Re: [請益] 誰會c++阿>.<
※ 引述《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)
討論串 (同標題文章)