//
6.编写一个函数,求两个数字的最大公约数。
public int GetCommonDivisor(int num1, int num2){
//辗转相除法
int remainder = 0;
while (num1 % num2 > 0) {
remainder = num1 % num2;
num1 = num2;
num2 = remainder;
}
return remainder;
}
//
7.编写一个函数,求两个数字的最小公倍数。
public int GetLowestCommonMultiple(int num1, int num2){
return num1 * num2 / GetCommonDivisor (num1, num2);
}
转载请注明原文地址: https://ju.6miu.com/read-1096.html