找出下标最小的数及其下标

来源:百度知道 编辑:UC知道 时间:2024/05/25 01:17:58
有一个10个元素的数组,各元素的值为25,15,48,75,96,35,87,45,25,69.编写程序,找出下标最小的数及其下标.并将数组各元素的值,最小数喝醉小数的下标在窗体上输出.

用vb的方法

Private Sub Command1_Click()
arr = Array(25, 15, 48, 75, 96, 35, 87, 45, 25, 69)
imin = 0
For i = 1 To UBound(arr)
If arr(i) < arr(imin) Then imin = i
Next i
Print "最小数是:"; arr(imin)
Print "下标是:"; imin
End Sub

a=suzu(0)
b=0
for i=1 to 9
if suzu(i)<a then
a=suzu(i)
b=i
endif
next
?"最小数是:";a
?"下标是:";b

Private Sub Form_Click()
Dim a(9) As Integer
Dim i As Integer, b As Integer, c As Integer
a(0) = 25
a(1) = 15
a(2) = 48
a(3) = 75
a(4) = 96
a(5) = 35
a(6) = 87
a(7) = 45
a(8) = 25
a(9) = 69
Me.Cls
b = a(0)
For i = 1 To 9
Print a(i),
If a(i) < b Then
b = a(i)
c = i
End If
Next
Print
Print "最小数是:" & b, ",下标是:" & c
End Sub