早教吧 育儿知识 作业答案 考试题库 百科 知识分享

VB程序设计题目!求一组数中所有偶数元素的平均值,要求:(1)编制一个自定义函数过程Even,计算数组中所有偶数元素的平均值.(2)编制一个事件过程FormClick,随机产生10个100以内的随机正整

题目详情
VB程序设计题目!
求一组数中所有偶数元素的平均值,要求:
(1)编制一个自定义函数过程Even,计算数组中所有偶数元素的平均值.
(2)编制一个事件过程Form_Click,随机产生10个100以内的随机正整数,通过调用Even函数输出偶数平均值.
Dim z As Integer
Private Sub a()
Dim x As Integer,y As Integer,z As Integer
x = 4 :y = 6 :z = x + y + z
Print x ; y ; z
End Sub
Private Sub Form_Click()
Dim x As Integer,y As Integer
x = 3 :y = 5 :z= z + x mod y
Call a()
Print x ; y ; z
End Sub
第二次单击窗体后,输出 ——————
▼优质解答
答案和解析
Private Function Even(intData() As Integer) As Long
Dim i As Long, sum As Long, ic As Long
sum = 0
ic = 0
For i = LBound(intData) To UBound(intData)
If ((intData(i) Mod 2) = 0) Then
sum = sum + intData(i)
ic = ic + 1
End If
Next
Even = sum / ic
End Function
Private Sub Form_Click()
Dim intData(9) As Integer, i As Integer
Randomize
Me.Cls
For i = 0 To 9
intData(i) = 1 + CInt(99 * Rnd)
Next
Me.Print Even(intData)
End Sub
看了 VB程序设计题目!求一组数中...的网友还看了以下: