产生30个1--100之间的随机整数,计算这30个数的平均值,找出30个数中数值大于平均值的数据,并统计出这些数Dim x(1 To 30) As IntegerDim sum As Integer,ave As IntegerDim i As IntegerDim count As Integersum = 0For i = 1 T
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/13 04:28:48
产生30个1--100之间的随机整数,计算这30个数的平均值,找出30个数中数值大于平均值的数据,并统计出这些数Dim x(1 To 30) As IntegerDim sum As Integer,ave As IntegerDim i As IntegerDim count As Integersum = 0For i = 1 T
产生30个1--100之间的随机整数,计算这30个数的平均值,找出30个数中数值大于平均值的数据,并统计出这些数
Dim x(1 To 30) As Integer
Dim sum As Integer,ave As Integer
Dim i As Integer
Dim count As Integer
sum = 0
For i = 1 To 30
Randomize
x(i) = Int(Rnd * 100) + 1
sum = sum + x(i)
Form1.Print x(i); Space(2);
If i Mod 5 = 0 Then Form1.Print
Next i
ave = sum / 30
Form1.Print "平均值:"; ave
Form1.Print "在平均值之上的数据是:"
For i = 1 To 30
If x(i) > ave Then
count = count + 1
Form1.Print x(i); Space(2);
If count Mod 5 = 0 Then Form1.Print
End If
Next i
Form1.Print
Form1.Print "共有"; count; "个在平均值之上."
这个也调试不出来,
产生30个1--100之间的随机整数,计算这30个数的平均值,找出30个数中数值大于平均值的数据,并统计出这些数Dim x(1 To 30) As IntegerDim sum As Integer,ave As IntegerDim i As IntegerDim count As Integersum = 0For i = 1 T
没问题啊,如图
Private Sub Command1_Click()
Dim x(1 To 30) As Integer
Dim sum As Integer, ave As Integer
Dim i As Integer
Dim count As Integer
sum = 0
For i = 1 To 30
Randomize
x(i) = Int(Rnd * 100) + 1
sum = sum + x(i)
Form1.Print x(i); Space(2);
If i Mod 5 = 0 Then Form1.Print
Next i
ave = sum / 30
Form1.Print "平均值:"; ave
Form1.Print "在平均值之上的数据是:"
For i = 1 To 30
If x(i) > ave Then
count = count + 1
Form1.Print x(i); Space(2);
If count Mod 5 = 0 Then Form1.Print
End If
Next i
Form1.Print
Form1.Print "共有"; count; "个在平均值之上."
End Sub