vb求最大公约数和最小公倍数
时间: 2023-12-03 12:37:11 浏览: 159
求最大公约数和最小公倍数
VB是一种编程语言,可以用来编写计算最大公约数和最小公倍数的程序。下面是一个简单的VB程序,可以计算两个数的最大公约数和最小公倍数:
```
Option Explicit
Dim m As Integer
Dim n As Integer
Dim t As Integer
Dim mn As Long
Dim r As Integer
Private Sub Command1_Click()
Label1.Caption = Val(mn / n)
End Sub
Private Sub Command2_Click()
Label2.Caption = Val(n)
End Sub
Private Sub Command3_Click()
m = Text1.Text
n = Text2.Text
mn = m * n
If m < n Then
t = m
m = n
n = t
End If
r = m Mod n
While r <> 0
m = n
n = r
r = m Mod n
Wend
Label1.Caption = Val(mn / n)
Label2.Caption = Val(n)
End Sub
Private Sub Command7_Click()
Label1.Caption = ""
Label2.Caption = ""
阅读全文