vb帮忙修修代码!辗转相减法求最大公约数运行 输好inputbox后 form是空白代码如下:Option ExplicitPrivate Sub form_load()Dim m As Long,n As Long,m1 As Long,n1 As Long,r As Long,t As Longm1 = InputBox("输入m1","求最大公
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/25 16:33:18
vb帮忙修修代码!辗转相减法求最大公约数运行 输好inputbox后 form是空白代码如下:Option ExplicitPrivate Sub form_load()Dim m As Long,n As Long,m1 As Long,n1 As Long,r As Long,t As Longm1 = InputBox("输入m1","求最大公
vb帮忙修修代码!辗转相减法求最大公约数
运行 输好inputbox后 form是空白
代码如下:
Option Explicit
Private Sub form_load()
Dim m As Long,n As Long,m1 As Long,n1 As Long,r As Long,t As Long
m1 = InputBox("输入m1","求最大公约数和最小公倍数")
n1 = InputBox("输入n1","求最大公约数和最小公倍数")
m = m1
n = n1
Do
If n > m Then
t = m
m = n
n = t
End If
r = m - n
If r = 0 Then Exit Do
m = n
n = r
Loop Until r = 0
Print m1; ","; n1; "的最大公约数是"; m
Print m1; ","; n1; "的最小公倍数是"; m1 * n1 / m
End Sub
vb帮忙修修代码!辗转相减法求最大公约数运行 输好inputbox后 form是空白代码如下:Option ExplicitPrivate Sub form_load()Dim m As Long,n As Long,m1 As Long,n1 As Long,r As Long,t As Longm1 = InputBox("输入m1","求最大公
PRINT有个缺点,如果被窗体挡一下 打印上去的文字就会消失,
你在FORM LOAD 中,用PRINT 是不行的,
因为在窗体还没出来之前就打印好了,出来是文字是会消失的,
你的代码是没错的 你用MSGBOX吧 我下面帮你改好了
或者放到其他控件里
Option Explicit
Private Sub form_load()
Dim m As Long,n As Long,m1 As Long,n1 As Long,r As Long,t As Long
m1 = InputBox("输入m1","求最大公约数和最小公倍数")
n1 = InputBox("输入n1","求最大公约数和最小公倍数")
m = m1
n = n1
Do
If n > m Then
t = m
m = n
n = t
End If
r = m - n
If r = 0 Then Exit Do
m = n
n = r
Loop Until r = 0
MsgBox m1 & "," & n1 & "的最大公约数是" & m & vbCrLf & _
m1 & "," & n1 & "的最小公倍数是" & m1 * n1 / m
End Sub