“辗转相除法”求解最小公倍数 Function LCM(ParamArray nums()) As Long Dim temp1 As Long, temp2 As Long, I As Long LCM = nums(0) For I = 1 To UBound(nums) temp1 = LCM temp2 = nums(I) LCM = LCM * temp2 Do If temp1 < temp2 Then temp = temp1 temp1 = temp2 temp2 = temp End If temp1 = temp1 Mod temp2 Loop While temp1 LCM = LCM / temp2 Next End Function '调用: MsgBox LCM(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
最小公倍数
最新推荐文章于 2023-05-25 23:07:14 发布