任意输入两个整数,求他们的最大公约数的VB程序 100
3个回答
展开全部
'点击窗体出现输入框,分别输入第2个整数,在窗体内就会出现最大公约数,代码如下:
Private Sub Form_Click()
Dim C As Long, D As Long, E As Long
C = InputBox("请输入第1个整数:")
D = InputBox("请输入第2个整数:")
E = Zdgys(C, D)
Print C; " 和 "; D; " 的最大公约数是:"; E
End Sub
'下面是自定义函数—最大公约数函数
Private Function Zdgys(ByVal A As Long, ByVal B As Long)
Dim R As Long
R = A Mod B
Do While R <> 0
A = B
B = R
R = A Mod B
Loop
Zdgys = B
End Function
展开全部
点击窗体出现输入框,分别输入第2个整数,在窗体内就会出现最大公约数,代码如下:
Private Sub Form_Click()
Dim C As Long, D As Long, E As Long
C = InputBox("请输入第1个整数:")
D = InputBox("请输入第2个整数:")
E = Zdgys(C, D)
Print C; " 和 "; D; " 的最大公约数是:"; E
End Sub
'下面是自定义函数—最大公约数函数
Private Function Zdgys(ByVal A As Long, ByVal B As Long)
Dim R As Long
R = A Mod B
Do While R <> 0
A = B
B = R
R = A Mod B
Loop
Zdgys = B
End Function
Private Sub Form_Click()
Dim C As Long, D As Long, E As Long
C = InputBox("请输入第1个整数:")
D = InputBox("请输入第2个整数:")
E = Zdgys(C, D)
Print C; " 和 "; D; " 的最大公约数是:"; E
End Sub
'下面是自定义函数—最大公约数函数
Private Function Zdgys(ByVal A As Long, ByVal B As Long)
Dim R As Long
R = A Mod B
Do While R <> 0
A = B
B = R
R = A Mod B
Loop
Zdgys = B
End Function
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Form_Click()
Dim a, b As Integer
Dim m, n, t, r As Integer
m = Val(InputBox("输入整数m"))
n = Val(InputBox("输入整数n"))
If m < n Then
t = m: m = n: n = t
End If
a = m '较小值赋给a
b = n '较大值赋给b
r = m Mod n
Do While r <> 0
m = n: n = r: r = m Mod n
Loop
Print a; ","; b; "的最大公约数"; n
End Sub
Dim a, b As Integer
Dim m, n, t, r As Integer
m = Val(InputBox("输入整数m"))
n = Val(InputBox("输入整数n"))
If m < n Then
t = m: m = n: n = t
End If
a = m '较小值赋给a
b = n '较大值赋给b
r = m Mod n
Do While r <> 0
m = n: n = r: r = m Mod n
Loop
Print a; ","; b; "的最大公约数"; n
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询