#include
#include
int fun_y(int,int);
int fun_b(int,int);
main()
{
int a,b,gy,gb;
printf("输入两个整数:\n");
scanf("%d%d",&a,&b);
gy=fun_y(a,b);
gb=fun_b(a,b);
printf("最大公约数是:%d\n最小公倍数是:%d\n",gy,gb);
}
int fun_y(int x,int y)
{
int z,i;
if(x>y)
z=sqrt(y);
else
z=sqrt(x);
for(i=z;i>=1;i--)
{
if(x%i==0&&y%i==0)
break;
}
return i;
}
int fun_b(int x,int y)
{
int z,i;
z=x*y;
for(i=x;i<=z;i++)
{
if(i%x==0&&i%y==0)
break;
}
return i;
}
以下是运行结果:
#include
int max,min;
void Func(int x1,int x2)
{
int m_biger,m_smler,temp;
if(x1>x2)
{
m_biger=x1;
m_smler=x2;
}
else
{
m_biger=x2;
m_smler=x1;
}
while(temp=m_biger%m_smler)
{
m_biger=m_smler;
m_smler=temp;
}
max=m_smler;
min=x1*x2/max;
}
void main()
{
int n1,n2;
printf("Please Input 2 number for compute:\nX1:\t");
scanf("%d",&n1);
printf("X2:\t");
scanf("%d",&n2);
Func(n1,n2);
printf("The greatest common denominator is:%d\n",max);
printf("The lowest common multiple is:%d\n",min);
}
#include"stdafx.h"
#include
int m;
void dayue(int a,int b);
void main()
{
int a,b;
cout<<"input a and b:";
cin>>a>>b;
dayue(a,b);
cout<<"最大公约数是"<
void dayue(int a,int b)
{
m=afor(;m>2;m--)
if(a%m+b%m==0) break;
}