1.最大公约数辗转相除法
int t;
while(b!=0){
t=a%b;
a=b;
b=t;
}
printf("the gcd is %d\n",a);
2.最小公倍数
最小公倍数乘以最大公约数等于两数乘积,所以最小公倍数等于两数乘积除以最大公约数。
include<stdio.h>
include<math.h>
int main(void){
printf("please input two number:");
int a=0,b=0;
scanf("%d %d",&a,&b);
int temp1=a,temp2=b;
int t;
while(b!=0){
t=a%b;
a=b;
b=t;
}
printf("the gcd is %d\n",a);
int zxg=temp1*temp2/a;
printf("the zxgbs is %d\n",zxg);
}
标签:temp2,公倍数,最小,int,最大公约数,printf From: https://www.cnblogs.com/zhongta/p/18152374