VB.NET程序设计题,紧急啊,明天考试了
发布网友
发布时间:2023-11-30 01:49
我来回答
共2个回答
热心网友
时间:2024-01-16 23:48
Public Class Form3
Dim A(19) As Integer '声明数组20个
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = ""
Label3.Text = ""
Randomize()
Dim i As Integer
For i = 0 To UBound(A)
A(i) = CInt(Rnd() * 400 + 100)'随机数100~500
Label1.Text &= A(i) & " "
If (i + 1) Mod 5 = 0 Then '每5个数就换行
Label1.Text &= vbCrLf
End If
Next
Dim mina As Integer
mina = Amin(A)
If mina > 0 Then
Label3.Text = "比第一个数组元素值大的数组元素中值最小的是:" & mina
Else
Label3.Text = "没有比第一个数组元素大数!"
End If
End Sub
Function Amin(ByVal Aa() As Integer) As Integer
Dim first As Integer
Dim tmpmin As Integer
Dim j, i As Integer
Dim tmpa() As Integer = A
first = A(0) '第一个数出来
For j = 1 To UBound(tmpa) ’从第二个数冒泡
tmpmin = tmpa(j)
For i = j To UBound(tmpa)
If tmpa(i) < tmpmin Then '从小数到大数冒泡
tmpa(j) = tmpa(i)
tmpa(i) = tmpmin
tmpmin = tmpa(j)
End If
Next
Next
For i = 0 To UBound(tmpa)
If tmpa(i) > first Then ’从小数开始比较,如果小比第一个元数大就退出
tmpmin = tmpa(i) ' 取到比第一个元数大的数
Exit For
End If
Next
Return tmpmin '返回值
End Function
End Class
热心网友
时间:2024-01-16 23:48
先找到比第一个大的,然后再找到里面最小的一个。追问这个我当然知道啊,我是要代码啊,我自己写的不知道对不对啊,