c语言中如何用辗转相除求最大公约数、求最小公倍数?

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/28 18:30:35
c语言中如何用辗转相除求最大公约数、求最小公倍数?

c语言中如何用辗转相除求最大公约数、求最小公倍数?
c语言中如何用辗转相除求最大公约数、求最小公倍数?

c语言中如何用辗转相除求最大公约数、求最小公倍数?
#include
void main()
{
int a,b,x,y,temp;
x = 34; y = 12;
if(x < y)
{
temp = x; x = y; y = temp;
}
a = x; b = y;
while(b != 0)
{
temp = a % b;
a = b;
b = temp;
}
printf("yue:%d\n",a);
printf("bei:%d\n",x*y / a);
}