English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

sub main()

Dim a() as integer={3,1,3,1,2,1,3}
Dim b(,) as integer={{3,4,3},{1,3,4},{1,1,3}}

Console.WriteLine(most(a)) "輸出最多次的數字
Console.WriteLine(most(b))
Console.Read

end sub

2007-01-09 14:05:12 · 1 個解答 · 發問者 Anonymous in 電腦與網際網路 程式設計

1 個解答

' VB6.0
Public Sub Most()
Dim a(6) As Integer
Dim b(2, 2) As Integer
Dim i, j, p, q, n, c(24, 1) As Integer
a(0) = 3: a(1) = 1: a(2) = 3: a(3) = 1: a(4) = 2: a(5) = 1: a(6) = 3
b(0, 0) = 3: b(0, 1) = 4: b(0, 2) = 3
b(1, 0) = 1: b(1, 1) = 3: b(1, 2) = 4
b(2, 0) = 1: b(2, 1) = 1: b(2, 2) = 3
For i = 6 To 0 Step -1
c(i, 0) = a(i)
c(i, 1) = 1
For j = i + 1 To 6
If a(i) = c(j, 0) Then
c(i, 1) = c(j, 1) + 1
Exit For
End If
Next j
Next i
n = c(0, 1)
For i = 1 To 6
If c(i, 1) > n Then n = i
Next i
For i = 0 To 6
If c(i, 1) = n Then Print "a 陣列中最多的元素是 " & c(i, 0) & ", 有 " & n & " 個."
Next i
Print ""
For i = 8 To 0 Step -1
q = i Mod 3
p = i \ 3
c(i, 0) = b(p, q)
c(i, 1) = 1
For j = i + 1 To 8
If c(i, 0) = c(j, 0) Then
c(i, 1) = c(j, 1) + 1
Exit For
End If
Next j
Next i
n = c(0, 1)
For i = 1 To 8
If c(i, 1) > n Then n = i
Next i
For i = 0 To 8
If c(i, 1) = n Then Print "b 陣列中最多的元素是 " & c(i, 0) & ", 有 " & n & " 個."
Next i
End Sub
如果有問題, 請來函討論. 不然, 我可能會錯失你再補充的疑點.

2007-01-10 10:07:56 · answer #1 · answered by JJ 7 · 0 0

fedest.com, questions and answers