fpbl.net
当前位置:首页 >> vB求一组数平均数 >>

vB求一组数平均数

Private Sub Command1_Click() Call pjs(Text1) End Sub Private Function pjs(txt As TextBox) Dim sum() As String, a As Single sum = Split(txt, ",") For i = 0 To UBound(sum) a = a + sum(i) Next i MsgBox "平均数为:" & a / i End Function

如果已经知道数组元素的个数 下面以20个元素的数组为例(数组下标从1开始): '从小到大排序: For i = 1 To 19 For j = 1 To 20 - i If a(j) > a(j + 1) Then n = a(j): a(j) = a(j + 1): a(j + 1) = n End If Next jNext iLabel1.Caption = "最大值为:" & a(20)

Private Sub Command1_Click() Dim myStr As String Dim s As Double Dim n As Long n = 0 s = 0 Do myStr = InputBox("请输入一个数,当输入AAA时结束输入并计算全部数的平均值.") If UCase(myStr) <> "AAA" Then If IsNumeric(myStr)

Private Function Even(intData() As Integer) As LongDim i As Long, sum As Long, ic As Longsum = 0ic = 0For i = LBound(intData) To UBound(intData) If ((intData(i) Mod 2) = 0) Then sum = sum +

定义一变量 pp将每次的结果累加写入pp最后求平均值pp=0for i=1 to 5 输入一组数,点击确定,出来一个结果(jg).pp=pp+jg i=i+1next ipppp=pp/5

这里只给出求平均值的算法,结果显示自己写吧,看前面,你应该有一定的基础了. dim s as integer s=0 for i = 0 to 6 s=s+a(i) next is=s/7

Private Sub Command1_Click() Dim a() Dim sum As Integer a = Array(1, 2, 3, 4, 5, 6) For i = 0 To 5 sum = sum + a(i) Next Print "总和为:"; sum Print "平均值:"; sum / 6 End Sub

最低0.27元/天开通百度文库会员,可在文库查看完整内容> 原发布者:磷and诗 产生20个0~1000的随机整数,放入一个数组中,然后输出这20个整数的平均值.程序运行后,单击命令按钮(名称为Command1),标题为“输出平均值”,即可

private sub command1_click() '计算平均数text1.text = inputbox("输入第一个数")text2.text = inputbox("输入第二个数")text3.text = inputbox("输入第三个数")text4.text = inputbox("输入第四个数")text5.text = inputbox("输入

你可以这样编写 private sub command1_click() dim ave! '定义一个存储平均值的变量 ave=(val(text1)+val(text2)+val(text3))/3 end sub

网站首页 | 网站地图
All rights reserved Powered by www.fpbl.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com