VB 求最大值

2025-02-26 12:30:37
推荐回答(3个)
回答1:

Private Sub Command1_Click()

Dim a(100) As Integer, b(100) As Single, c(100) As String, max As Single

Open "d:\1111.txt" For Input As #1

Line Input #1, s$

Do While Not EOF(1)

  i = i + 1

  Input #1, a(i), b(i)

  Line Input #1, c(i)

Loop

n = i

max = b(1)

For i = 2 To n

  If max! < b(i) Then max = b(i)

Next i

Print "max="; max

Print "date", "speed", "fx"

For i = 1 To n

  If b(i) = max Then Print a(i), b(i), c(i)

Next i

End Sub

回答2:

1、从文件中读取内容;
2、将内容赋值到一个2维数组中;
3、对这个数组循环一遍,就可以找到你要的最大数字对应的fx。

回答3:

表面上看这些代码没有太大的问题,MAX函数有点小问题,就是如果参数数组下标不是从0开始时,程序可能会发生错误或不返回正确的结果
求采纳为满意回答。