# VB 排序

Dim student(,) = {{93001, &quot;John&quot;, 89, 90, 77}, _

{93002, &quot;Mary&quot;, 80, 95, 97}, _

{93003, &quot;Bill&quot;, 88, 71, 71}, _

{93004, &quot;tksg&quot;, 85, 77, 76}, _

{93005, &quot;skyg&quot;, 97, 60, 78}}

Dim total_score(5), avg_score(5)

For i As Integer = 0 To 4

For j As Integer = 2 To 4

total_score(i) += student(i, j)

Next

Next

For i As Integer = 0 To 5

avg_score(i) = Math.Round(total_score(i) / 3)

Next

TextBox1.Text = &quot;學號 姓名 數學 國文 英文 總分 平均&quot; &amp; vbCrLf

For i As Integer = 0 To 3

For j As Integer = i + 1 To 4

If avg_score(i) &gt; avg_score(j) Then

Dim c As Integer = avg_score(i)

avg_score(i) = avg_score(j)

avg_score(j) = c

End If

Next

Next

For i As Integer = 0 To 3

For j As Integer = i + 1 To 4

If total_score(i) &gt; total_score(j) Then

Dim c As Integer = total_score(i)

total_score(i) = total_score(j)

total_score(j) = c

End If

Next

Next

For i As Integer = 0 To 4

For j As Integer = 0 To 4

TextBox1.Text &amp;= student(i, j) &amp; &quot; &quot;

Next

TextBox1.Text &amp;= total_score(i) &amp; &quot; &quot;

TextBox1.Text &amp;= avg_score(i) &amp; vbCrLf

Next

### 1 個解答

• 屁德
Lv 4
1 0 年前
最佳解答

For i As Integer = 0 To 4

For j As Integer = 0 To 4

a(i) &= student(i, j) & " "

Next

a(i) &= total_score(i) & " "

a(i) &= avg_score(i) & " " & vbCrLf

Next

For i As Integer = 0 To 3

For j As Integer = i To 0 Step -1

If avg_score(j) < avg_score(j + 1) Then

Dim b As String = avg_score(j)

avg_score(j) = avg_score(j + 1)

avg_score(j + 1) = b

Dim c As String = a(j)

a(j) = a(j + 1)

a(j + 1) = c

End If

Next

Next

For i As Integer = 4 To 0 Step -1

TextBox1.Text &= a(i)

Next