dim i as integer
for i = 1 to 5
swap( a(i), a( 11 - i ) )
next iprivate sub swap( a as integer, b as integer )
dim c as integer
c = a
a = b
b = c
end sub
for i = 1 to 5
swap( a(i), a( 11 - i ) )
next iprivate sub swap( a as integer, b as integer )
dim c as integer
c = a
a = b
b = c
end sub
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 600
Left = 1935
TabIndex = 0
Top = 1125
Width = 1125
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim a(1 To 10) As IntegerPrivate Sub Command1_Click()
Dim i As Integer
For i = 1 To 5
swap a(i), a(11 - i)
Next i
Debug.Print "after"
For i = 1 To 10
Debug.Print a(i)
Next i
End SubPrivate Sub swap(a As Integer, b As Integer)
Dim c As Integer
c = a
a = b
b = c
End SubPrivate Sub Form_Load()
Dim i As Integer
For i = 1 To 10
a(i) = Val(InputBox("input" & Str(i)))
Next i
Debug.Print "before"
For i = 1 To 10
Debug.Print a(i)
Next iEnd Subthis is the result
before
4
5
5
14
5
1
5
1
4
2
after
2
4
1
5
1
5
14
5
5
4
dim intPara(1 to 10) as integer
For I = 1 To 5
swap intPara(I), intPara(11 - I)
Next IEnd Sub
Private Sub swap(a, b As Integer)
Dim c As Integer
c = a
a = b
b = c
End Sub
那我就写一段QB的代码吧
BTW, 算法比较弱,没有什么结构Option Base 1Dim A(10) As Integer, Temp(5) As Integer
Dim i As Integer'Input
Print "Input 10 integers:"
For i = 1 To 10
input A(i)
Next i
'Out (Before)
Print "Before:"
For i = 1 To 10
Print A(i);
Next i
Print'Swap
For i = 1 To 5 'Push last half into Temp
Temp(i) = A(i + 5)
Next i
For i = 1 To 5 'Move first half to second half
A(i + 5) = A(5 - i + 1)
Next i
For i = 1 To 5 'Pop Temp to first half
A(i) = Temp(5 - i + 1)
Next i'Output (after)
Print "After:"
For i = 1 To 10
Print A(i);
Next i