附:送上几例经典的算法
求最大公约数和最小公倍数
Private Sub Command3_Click()
Dim m1%, m%, n%, n1%, r%, b%
m1 = Val(InputBox("输入一个数:"))
n1 = Val(InputBox("请输入另一个数:"))
If m1 > n1 Then m = m1: n = n1 Else m = n1: n = m1
Do
r = m Mod n
If r = 0 Then Exit Do
m = n
n = r
Loop
Print m1; "和"; n1; "的最大公约数为:"; n
b = m1 * n1 / n
Print m1; "和"; n1; "的最小公倍数为:"; b
End Sub
求100到200之间所有的素数(质数)
Private Sub Command2_Click()
Dim i%, m%
For m = 101 To 199 Step 2
For i = 2 To Int(Sqr(m))
If (m Mod i) = 0 Then GoTo notnextM ''一旦被2到sqr(m)的数整除就转到下一个数
Next i
Print m
notnextM:
Next m
End Sub
注意!程序中使用了GoTo语句!