Dim a As Integer
Dim b As Single
Dim Sj() As Single
Dim He As Single
Dim I As Integer
ReDim Sj(a)
For I = 1 To a
Sj(I) = InputBox("请输入第" &I &"个数字:")
He = He + Sj(I)
Next I
b = He / a
For I = 1 To a
Sj(0) = Sj(0) + (Sj(I) - b) ^ 2
Next I
Print "这" &a &"个数的方差是:" &Sj(0) /哪轿巧李键 a
End Sub
Dim a() As DoublePrivate Sub Command1_Click()
Do
i = i + 1
temp = InputBox("请羡兆喊输入数字,输兄野入s结猜腔束输入")
If temp <>"s" Then
ReDim Preserve a(i) As Double
a(i) = temp
Sum = Sum + a(i)
Else
Dim temp1 As Double
For j = 1 To UBound(a)
temp1 = temp1 + (a(j) - (Val(Sum) / (i - 1))) ^ 2
Next
MsgBox "方差为" &temp1
Exit Do
End If
Loop
End Sub
Private Sub Command1_Click()Cls
Randomize (Timer)
Dim Score() As Integer
Const n As Integer = 100
ReDim Score(n - 1)
Dim Sum As Double, Average As Double, VarianceSum As Double, Varianc As Integer, StandardDeviation As Double
For i = LBound(Score) To UBound(Score)
Score(i) = Int(Rnd * 50 + 50)
Sum = Sum + Score(i)
Print Score(i)
森枯 If (i + 1) Mod 10 = 0 Then Print
Next i
此销洞 Print
Average = Sum / n
For i = LBound(Score) To UBound(Score)
VarianceSum = VarianceSum + (Score(i) - Average) ^ 2
Next i
Variance = VarianceSum / n
StandardDeviation = Sqr(Variance)
Print 斗清"Sun =" Sum
Print "n =" n
Print "Average =" Average
Print "Variance =" Variance
Print "StandardDeviation =" StandardDeviation
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)