最大公约数 和 最小公倍数
1 #include <stdio.h> 2 3 int iGcd(int iU, int iV) 4 { 5 int iRemainder = iU%iV; 6 while(iRemainder != 0) 7 { 8 iU = iV; 9 iV = iRemainder; 10 iRemainder = iU%iV; 11 } 12 return iV; 13 } 14 15 int iLcm(int iU, int iV) 16 { 17 return (iU*iV)/iGcd(iU, iV); 18 } 19 20 int main() 21 { 22 printf("%d %d\n", iGcd(6, 4), iLcm(6, 4)); 23 return 0; 24 }
My Github Blog: mdgsf.github.io

浙公网安备 33010602011771号