C語言練習(xí)題
從鍵盤輸入兩個(gè)數(shù)m和n,求其最大公約數(shù)和最小公倍數(shù)。
實(shí)現(xiàn)方法如下:
main()
{
int m,n,a,b;
int p,r,temp;
printf("Please input 2 integer(m,n):");
scanf("%d,%d",&m,&n);
a = m; b = n;
if(b<a)
{
temp = a;
a = b;
b = temp;
}
p = a * b;
while(a != 0)
{
r = b % a;
b = a;
a = r;
}
printf("The Greatest Common Divisor %d and %d is: %d/n",m,n,b);
printf("The Least Common Multiple %d and %d is: %d/n",m,n,p/b);
}
運(yùn)行結(jié)果為:

新聞熱點(diǎn)
疑難解答
圖片精選