VB程序设计:键盘输入10个整数,输出其中的最大数和平均值,并将这10个数从小到大排序输出到窗体上。

2024-11-08 12:40:14
推荐回答(2个)
回答1:

form添加一个按钮,点击就是结果

Private Sub Command1_Click()
Dim i, j, k, sum, imax, iavg, a(1 To 10)
j = 0: sum = 0: imax = 0: iavg = 0
For i = 1 To 10
Do
j = InputBox("请输入第 " & i & " 个整数:")
Loop While IsNumeric(j) = False
a(i) = j
sum = sum + j
If j > imax Then imax = j
Next i
iavg = sum / 10

For i = 1 To 9
For j = i + 1 To 10
If a(j) < a(i) Then
k = a(j)
a(j) = a(i)
a(i) = a(j)
End If
Next j
Next i

For i = 1 To 10
Print a(i)
Next i
End Sub

回答2:

循环对比排列.
然后+之/10
输出.