VB试题,求高手解答
第一题:2^1+......(2n)^(2n-1)第二题:[20,80]..能被3整除或者能被5整除的数的和第三题:求n个随机的[20,100]的里面的数的偶数和来个高手...
第一题: 2^1+......(2n)^(2n-1)第二题 :[20,80]..能被3整除或者能被5整除的数的和第三题:求n个随机的[20,100]的里面的数的偶数和来个高手速度解答,万分感谢
展开
2个回答
展开全部
速采纳,答题进行中!!!
Private Sub Command1_Click()
'第一题: 2^1+......(2n)^(2n-1)
Dim i As Long, n As Integer
Do While True
n = InputBox("请输入一个整数,数值请小于5:")
If IsNumeric(n) Then Exit Do
Loop
Dim Sum As Long
For i = 1 To n
Sum = Sum + (2 * i) ^ (2 * i - 1)
Next
Print Sum
End Sub
Private Sub Command2_Click()
'第二题 :[20,80]..能被5整除的数的和
Dim i As Long
Dim Sum As Long
For i = 20 To 80
If i Mod 5 = 0 Then Sum = Sum + i '能被5整除的数的和
'If i Mod 3 = 0 Then Sum = Sum + i '能被3整除的数的和
Next
Print Sum
End Sub
Private Sub Command3_Click()
'第三题:求n个随机的[20,100]的里面的数的偶数和
Dim i As Long, n As Integer, m As Integer
Do While True
n = InputBox("请输入一个整数,数值请小于5:")
If IsNumeric(n) Then Exit Do
Loop
Randomize
Dim Sum As Long
For i = 1 To n
m = Int(Rnd * 81 + 20)
If m Mod 2 = 0 Then
Print m;
Sum = Sum + m
End If
Next
Print Sum
End Sub
请在VB窗体中加入3个Command1,2,3按钮进行测试!
完成!!
展开全部
for i=1 to n
sum=sum+(2n)^(2n-1)
next
print sum
for i=20 to 80
if i mod 3=0 or i mod 5=0 then
sum=sum+i
endif
next
print sum
for i=1 to n
randomize
s=int(rnd*81+20)
if s mod 2=0 then
sum=sum+s
endif
next
print sum
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询