VB程序设计:键盘输入10个整数,输出其中的最大数和平均值,并将这10个数从小到大排序输出到窗体上。
2个回答
展开全部
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询