VB程序设计的几个问题谁能帮给下答案啊,急,求高手解答 10
1.求两个正整数的最大公约数和最小公倍数2.求1-500之间5的倍数的和3.100-300之间或3或7的倍数和这3个程序。。。谢谢各位了...
1.求两个正整数的最大公约数和最小公倍数
2.求1-500之间5的倍数的和
3.100-300之间或3或7的倍数和
这3个程序。。。谢谢各位了 展开
2.求1-500之间5的倍数的和
3.100-300之间或3或7的倍数和
这3个程序。。。谢谢各位了 展开
2个回答
展开全部
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
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询