willsun888
5/7/2013 - 6:08 AM

非递归求最小公倍数(Least Common Multiple)和最大公约数(Greatest Common Divisor)

非递归求最小公倍数(Least Common Multiple)和最大公约数(Greatest Common Divisor)

#include<stdio.h>
void main()
{
int a,b,num1,num2,temp;
printf("please input num1 and num2 \n");
scanf("%d%d",&num1,&num2);
if(num1 > num2)
{
a = num1;
b = num2;
}
else
{
a = num2;
b = num1;
}

while(b > 0)
{
temp = a % b;
a = b;
b = temp;
}
printf("最大公约数是%d\n最小公倍数是%d\n",a,(num1 * num2) / a);
}