C语言练习题
从键盘输入两个数m和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);}
运行结果为: