|
供参考。
- Sub 最小公倍数()
- Dim shu$, Temp, s() As Integer, gbs, maxs
- shu = Application.InputBox("输入两个或两个以上自然数,数字中间用逗号隔开:", "输入", Type:=2)
- Temp = Split(Replace(Replace(shu, ",", " "), ",", " "))
- ReDim s(0 To UBound(Temp))
- shu = ""
- For i = 0 To UBound(s)
- shu = IIf(i = 0, "", shu & ",") & Temp(i)
- s(i) = Temp(i)
- If maxs < s(i) Then maxs = s(i)
- Next
- shu = "[" & shu & "] = "
- Do
- gbs = gbs + maxs
- For i = 0 To UBound(s)
- If Not (gbs Mod s(i)) = 0 Then Exit For
- Next
- If i > UBound(s) Then Exit Do
- Loop
- MsgBox "最小公倍数 " & shu & gbs
- End Sub
复制代码 |
|