问一道VB编程题
- 提问者网友:活着好累
- 2021-08-24 12:23
- 五星知识达人网友:人類模型
- 2021-08-24 13:30
Option Base 1
Private Sub Command1_Click()
a = InputBox("请输入一个正整数")
b = InputBox("请输入一个正整数")
Text3.Text = "您输入了" & a & "和" & b
Dim d() As Integer
If a > b Then
c = Val(a)
Else
c = Val(b)
End If
ReDim d(c) As Integer
For i = 1 To c
If Val(a) Mod i = 0 And Val(b) Mod i = 0 Then
d(i) = i
Text1.Text = d(i)
End If
Next i
g = Int(Text1.Text)
f = (a \ g) * (b \ g) * g
Text2.Text = f
End Sub
- 1楼网友:过活
- 2021-08-24 13:35
给你写一个函数,自己调用:
'最大公约数
Function GYS(ByVal num1 As Integer, ByVal num2 As Integer)As Integer
While (num1<>num2)
if (num1>num2) then
num1=num1-num2
else
num2=num2-num1
end if
Wend
return num1
End Function
'最小公倍数:
Function GBS (ByVal num1 As Integer, ByVal num2 As Integer, ByVal gbs As Integer)
return num1*num2/gbs
End Function
'主函数调用
'求最大公约数:GYS(4,2)
求最小公倍数: GBS(4,2,GYS(4,2))