1.求两个正整数的最大公约数和最小公倍数
Private Sub Command1_Click()
Dim m As Long, n As Long
m = Val(InputBox("请输入一个正整数"))
n = Val(InputBox("请再输入一个正整数"))
If m > n Then
Call qiujie(m, n)
ElseIf m < n Then
Call qiujie(n, m)
Else
Print "两个正整数的最大公约数和最小公倍数皆为" & m
End If
End Sub
'下面是求解子程序,gy为公约数,gb为公倍数
Function qiujie(x, y)
Dim gy, gb
gy = y
Do
If x Mod gy = 0 And y Mod gy = 0 Then
Print "两个正整数的最大公约数为" & gy
Exit Do
End If
gy = gy - 1
Loop Until gy <= 0
gb = x
Do
If gb Mod x = 0 And gb Mod y = 0 Then
Print "两个正整数的最大公倍数为" & gb
Exit Do
End If
gb = gb + 1
Loop Until gb > x * y
End Function
2.求1-500之间5的倍数的和
Private Sub Command1_Click()
Dim n, sum
For n = 1 To 500
If n Mod 5 = 0 Then
sum = sum + n
End If
Next n
Print "1-500之间5的倍数的和为" & sum
End Sub
3.100-300之间或3或7的倍数和
Private Sub Command1_Click()
Dim n, sum
For n = 100 To 300
If n Mod 3 = 0 Or n Mod 7 = 0 Then
sum = sum + n
End If
Next n
Print "100-300之间或3或7的倍数和为" & sum
End Sub
1.Private Sub Form_click()
Dim a%, b%
a =val( InputBox("请输入2个正整数", "输入", "0"))
b = val(InputBox("请输入2个正整数", "输入", "0"))
t = a
k = 1
While k <> 0
k = t Mod b
t = t + a
Wend
t = t - a
Print a, b; "的最小公倍数为:"; t
Print a, b; "的最大公约数为:"; a * b / t
End Sub
2.Private Sub Form_Click()
For i = 1 To 500
If i Mod 5 = 0 Then
s = s + i
End If
Next i
Print s
End Sub
3.Private Sub Form_Click()
For i = 100 To 300
If i Mod 3 = 0 Or i Mod 7 = 0 Then
s = s + i
End If
Next i
Print s
End Sub