展开全部
1、遍历数组进行比较查找即可。
2、vb6示例代码:
Option Explicit
Private Sub Command1_Click()
Randomize Timer
Dim a(9) As Integer, i As Integer
Dim x, Fp As Integer, Zp As Integer
For i = 0 To 9 '模拟生成一个随机数组
a(i) = 50 - Rnd * 100
Debug.Print a(i); " ";
Next
Debug.Print
Fp = -32768: Zp = 32767
For Each x In a '遍历数组进行比较
If x > 0 Then
If Zp > x Then Zp = x
Else
If Fp < x Then Fp = x
End If
Next
Debug.Print "负数中的最大数是:"; Fp; " 正数中的最小数是:"; Zp
End Sub
2、vb6示例代码:
Option Explicit
Private Sub Command1_Click()
Randomize Timer
Dim a(9) As Integer, i As Integer
Dim x, Fp As Integer, Zp As Integer
For i = 0 To 9 '模拟生成一个随机数组
a(i) = 50 - Rnd * 100
Debug.Print a(i); " ";
Next
Debug.Print
Fp = -32768: Zp = 32767
For Each x In a '遍历数组进行比较
If x > 0 Then
If Zp > x Then Zp = x
Else
If Fp < x Then Fp = x
End If
Next
Debug.Print "负数中的最大数是:"; Fp; " 正数中的最小数是:"; Zp
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询