c语言编程,输入两整数,用辗转相除法计算这两个整数的最大公约数和最小公悖数

2024-12-05 03:04:24
推荐回答(2个)
回答1:

#include

int main()

{int a,b,r,lcm,gcd;

scanf("%d%d",&a,&b);

lcm=a*b;

while(r=a%b)

{a=b;

b=r;

}

gcd=b;

lcm/=gcd;

printf("最大公约数=%d\n最小公倍数=%d\n",gcd,lcm);

return 0;

}

回答2:

#include unsigned int gcd ( unsigned int a,unsigned int b) { unsigned int max,min ; max=a; min=b; do { if ( max < min ) { int temp=max ; max=min; min=temp ; } max -= min ; } while( max != min ) ; return min ; } int main( void