vb问题:任意输入三十个数,请编写程序能计算其和,平均值,平方和
这个代码对不对,怎么不能运行呢PrivateSubForm_Load()Dima(1To30),w%,r%,s%Dimi%w=0:r=0:s=0Fori=1To5a(i)...
这个代码对不对,怎么不能运行呢
Private Sub Form_Load()
Dim a(1 To 30), w%, r%, s%
Dim i%
w = 0: r = 0: s = 0
For i = 1 To 5
a(i) = Val(InputBox("请输入30个数"))
Next i
w = w + a(i): s = s + a(i) ^ 2
r = w / 30
Print "和为" & w
Print "平均值为" & r
Print "平方和为" & s
End Sub 展开
Private Sub Form_Load()
Dim a(1 To 30), w%, r%, s%
Dim i%
w = 0: r = 0: s = 0
For i = 1 To 5
a(i) = Val(InputBox("请输入30个数"))
Next i
w = w + a(i): s = s + a(i) ^ 2
r = w / 30
Print "和为" & w
Print "平均值为" & r
Print "平方和为" & s
End Sub 展开
2个回答
展开全部
Private Sub Command6_Click()
Dim ss As String, s1 As Single, s2 As Single, s3 As Single
Dim sL As Variant
ss = InputBox("请输入30个数,用逗号','隔开")
sL = Split(ss, ",")
If UBound(sL) <> 30 Then
MsgBox "数字不对"
Exit Sub
End If
s1 = 0
s2 = 0
For i = 0 To UBound(sL)
s1 = s1 + sL(i)
s2 = s2 + sL(i) ^ 2
Next
s3 = s1 / (UBound(sL) + 1)
Print "和为" & s1; ",平均值为" & s3; ",平方和为" & s2
End Sub
Dim ss As String, s1 As Single, s2 As Single, s3 As Single
Dim sL As Variant
ss = InputBox("请输入30个数,用逗号','隔开")
sL = Split(ss, ",")
If UBound(sL) <> 30 Then
MsgBox "数字不对"
Exit Sub
End If
s1 = 0
s2 = 0
For i = 0 To UBound(sL)
s1 = s1 + sL(i)
s2 = s2 + sL(i) ^ 2
Next
s3 = s1 / (UBound(sL) + 1)
Print "和为" & s1; ",平均值为" & s3; ",平方和为" & s2
End Sub
更多追问追答
追答
请改一下
s1 = s1 + Val(sL(i))
s2 = s2 + Val(sL(i)) ^ 2
注意你的逗号要是半角的即 不是"," 是","
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Form_Load()
Dim a(1 To 30), w%, r%, s%
Dim i%
w = 0
r = 0
s = 0
For i = 1 To 30
a(i) = Val(InputBox("请输入" & i & "个数"))
w = w + a(i)
s = s + a(i) * a(i)
r = w / 30
Next i
Print "和为" & w
Print "平均值为" & r
Print "平方和为" & s
End Sub
Dim a(1 To 30), w%, r%, s%
Dim i%
w = 0
r = 0
s = 0
For i = 1 To 30
a(i) = Val(InputBox("请输入" & i & "个数"))
w = w + a(i)
s = s + a(i) * a(i)
r = w / 30
Next i
Print "和为" & w
Print "平均值为" & r
Print "平方和为" & s
End Sub
更多追问追答
追问
为什么还是显示不了结果呢,谢谢
追答
Private Sub Form_Load()
Dim a(1 To 30), w%, r%, s%
Dim i%
w = 0
r = 0
s = 0
For i = 1 To 30
a(i) = Val(InputBox("请输入" & i & "个数"))
Next i
For i =1 to 30
w = w + a(i)
s = s + a(i) * a(i)
r = w / 30
Next i
Print "和为" & w
Print "平均值为" & r
Print "平方和为" & s
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询