VB问题。用inputbox输入3个数字。然后求出平均数,用msgbox表示出来

来源:百度知道 编辑:UC知道 时间:2024/07/04 08:14:42
用inputbox输入3个数字。然后求出平均数,用msgbox表示出来

dim a ,b ,c as integer,x as single
a=inputbox("请输入一个数")
b=inputbox("请输入一个数")
c=inputbox("请输入一个数")
x=(a+b+c)/3
msgbox("平均数为" &x)

Dim a(2), i
For i = 0 To 2
a(i) = CInt(InputBox("请输入一个数"))
Next
MsgBox "平均数为" & CStr((a(0) + a(1) + a(2)) / 3)

Sub 平均数()
Dim i As Integer
Dim x As Double
x = 0
For i = 1 To 3
x = x + InputBox("请输入第" & i & "个数字:")
Next i
MsgBox ("3个数字的平均数为:" & x / 3)
End Sub

一楼答案就很好了