C语言之最大公约数与最小公倍数

时间:2023-11-28 14:06:38

#include<stdio.h>
int main()
{
int num1, num2,temp;
scanf("%d%d",&num1,&num2);
int t1 = num1;
int t2 = num2;
while (num2 != 0)
{
temp = num1%num2;
num1 = num2;
num2 = temp;
printf("num1=%d,num2=%d,temp=%d\n", num1, num2, temp);
}
printf("最大公约数为%d\n", num1);
printf("最小公倍数为%d\n",(t1*t2)/num1);

return 0;
}