VB编程,将一堆数组中10个元素向右循环移n位 20
例如,数组各元素的值依次为:1、3、5、7、9、2、4、6、8、10;向右移3次后各元素的值为6、8、10、1、3、5、7、9、2、4...
例如,数组各元素的值依次为:1、3、5、7、9、2、4、6、8、10;向右移3次后各元素的值为6、8、10、1、3、5、7、9、2、4
展开
3个回答
展开全部
办法很多,给你一个方法,参考一下吧。
Private Sub Command1_Click()
Dim A(9) As Integer, i As Integer, B(2) As Integer
For i = 0 To 4
A(i) = 2 * i + 1
Next
For i = 5 To 9
A(i) = (i - 4) * 2
Next i
For i = 0 To 2
B(i) = A(i + 7)
Next i
For i = 9 To 3 Step -1
A(i) = A(i - 3)
Next i
For i = 0 To 2
A(i) = B(i)
Next i
For i = 0 To 9
Debug.Print A(i);
Next i
End Sub
Private Sub Command1_Click()
Dim A(9) As Integer, i As Integer, B(2) As Integer
For i = 0 To 4
A(i) = 2 * i + 1
Next
For i = 5 To 9
A(i) = (i - 4) * 2
Next i
For i = 0 To 2
B(i) = A(i + 7)
Next i
For i = 9 To 3 Step -1
A(i) = A(i - 3)
Next i
For i = 0 To 2
A(i) = B(i)
Next i
For i = 0 To 9
Debug.Print A(i);
Next i
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
定义一个新的数组存储新的顺序。这个是大概的算法,但是已经忘记了vb的语法,希望也可以帮倒你啦。
dim old[10]={1,3,5,7,9,2,4,6,8,10}
dim new[10]
dim n,i,newi
n=3
i=0
while i<10
newi=i+3
if newi>=10 then
newi=newi+1-10
end if
new[newi]=old[i]
i++
do while
dim old[10]={1,3,5,7,9,2,4,6,8,10}
dim new[10]
dim n,i,newi
n=3
i=0
while i<10
newi=i+3
if newi>=10 then
newi=newi+1-10
end if
new[newi]=old[i]
i++
do while
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Option Explicit
Private Sub Form_Click()
Dim a(10) As Integer
Dim i As Integer
Dim b(10) As Integer
a(0) = 1: a(1) = 3: a(2) = 5: a(3) = 7: a(4) = 9
a(5) = 2: a(6) = 4: a(7) = 6: a(8) = 8: a(9) = 10
For i = 0 To 9
b(i) = a((i + n) Mod 9)
Print b(i)
Next
End Sub
n是称的位数,+是左移-是右移
Private Sub Form_Click()
Dim a(10) As Integer
Dim i As Integer
Dim b(10) As Integer
a(0) = 1: a(1) = 3: a(2) = 5: a(3) = 7: a(4) = 9
a(5) = 2: a(6) = 4: a(7) = 6: a(8) = 8: a(9) = 10
For i = 0 To 9
b(i) = a((i + n) Mod 9)
Print b(i)
Next
End Sub
n是称的位数,+是左移-是右移
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询