作者Joybo (Joybo)
看板Ju-88
标题Re: [请益] 谁会c++阿>.<
时间Mon Apr 19 18:00:58 2004
※ 引述《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)