Dim n, m As Integer
Dim a() As Integer
n = InputBox("请输入要产生随机数的个数n")
m = InputBox("请输入要移动的位数m")
ReDim a(n)
str = "生成数组为" & vbCrLf
For i = 1 To n
a(i) = Int(Rnd() * 90 + 10)
str = str & a(i) & " "
Next
Dim b(m), c(n) As Integer
For i = 1 To m
b(i) = a(n - m + i)
Next
For i = 1 To m
c(i) = b(i)
Next
For i = m + 1 To n
c(i) = a(i - m)
Next
str = str & vbCrLf & "移动后的数组为" & vbCrLf
For i = 1 To n
str = str & c(i) & " "
Next
TextBox6.Text = str
Private Sub Command1_Click()Dim a(1 To 7) As Integer
For i = 1 To 7
a(i) = i '赋初值,生成第一个标准数组
Print a(i)
Next i
For i = 1 To 7
t = a(7) '最右1为暂存
For j = 6 To 1 Step -1
a(j + 1) = a(j)'其余6位向右移一位
Next j
a(1) = t '暂存的移入最左
For j = 1 To 7
Print a(j)
Next j
Next i
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)