#include
using namespace std;
#define SWAP(a, b) {a^=b; b^=a; a^=b;}
#define PI 3.1415926
#define P 1e-6
// 求和
int f(int n, int m)
{
int sum = 0;
while( n <= m )
sum += (n++);
return sum;
}
// 圆环面积
double area(double r1, double r2)
{
if( r1P )
return 0.0;
else
return PI * (r2*r2 - r1*r1);
}
// 圆环周长
double length(double r1, double r2)
{
if( r1return 0.0;
else
return 2.0 * PI * (r1 + r2);
}
// 素数判断
int isPrime(int x)
{
if( x == 2 )
return 1;
if( x<2 || !(x&1) )
return 0;
for(int i = 3; i*i <= x; i+=2)
if( x%i == 0 )
return 0;
return 1;
}
// 最大公约数
unsigned gcd(unsigned x, unsigned y)
{
if( x < y ) SWAP(x, y);
while( y > 0 ){
unsigned t = x % y;
x = y;
y = t;
}
return x;
}
// 最小公倍数
unsigned lcm(unsigned x, unsigned y)
{
return x * y / gcd(x,y);
}
int main(void)
{
return 0;
}
因为字数限制,我就只写方法,你自己写实现的过程
1.
#include
using namespace std;
int fum(int n,int m){
int sum=0,i,temp;
if(n>m){
temp=n;
n=m;
m=temp;
}
for(i=n;i<=m;i++){
sum+=i;
}
return sum;
}
2.
#include
using namespace std;
void area(double r1,double r2){
double temp;
if(r1
r1=r2;
r2=temp;
}
cout<<"内环为"<
3.
#include
using namespace std;
int prime(int n){
int count=0,i;
for(i=2;i<=n;i++){
if(n%i==0){
count++;
}
}
if(count>=2){
return 0;
}else{
return 1;
}
}
4.
#include
using namespace std;
int maxGYS(int numA,int numB){
int temp,result=0;
if(numA
numA=numB;
numB=temp;
}
result=numA%numB;
while(result!=0){
numA=numB;
numB=result;
result=numA%numB;
}
return numB;
}
int minGBS(int numA,int numB){
return numA*numB/maxGYS(numA,numB);
}
第1题
#include stdio.h
int f(int n,int m);
void main()
{
int n,m;
scanf("%d%d",&n,&m);
printf("%d",f(n,m));
}
int f(int n,int m)
{
int i,s=0;
for(i=n;i<=m;i++)
s+=i;
return(s);
}