|
#include<stdio.h>//辗转相除法求两个正整数最大公约数,间接最小公倍数
void main()
{
int m,n,max,min,p,r;
printf("please input two integers:(use comma to separate them)\n");
scanf("%d,%d",&m,&n);
if(m>n)
{
p=n;
n=m;//有注释的程序容易被看懂,因为说的是人话,机器还没理解到那种程度,如果谁要是编一个中国人用的汉字程序就好了
m=p;//这一部分的作用就是n大m小
}
max=n;
min=m;
while(m!=0)//这里只能是m,因为r还没算出来
{
r=n%m;
n=m;
m=r;
}
printf("their greatest common divisor:%d\n",n);
printf("their leatest common multiple:%d\n",max*min/n);
}
|
|