vb 解题过程 Option Base 1 Private Sub Command1_Click() Dim s() As Integer i j k n as integer
Dimkasinteger,nasintegern=3Redims(n,n)i=1j=ns(i,j)=1ForK=1Ton*n-1Ifi+1>nTheni=n-j+2j=...
Dim k as integer ,n as integer
n=3
Redim s (n,n)
i=1 j=n
s(i,j) =1
For K =1 To n*n-1
If i+1>n Then
i=n-j+2 j=1
Else if i+1<=n and j+1>n then
j=j-i i=1
else i=i+1 j=j+1
end if
s(i,j)=k
next k
for i =1 to n
for j=1 to n
prints(i,j)
next j
print
next i
end sub
帮我点播一下 只要懂 可以加分啊 展开
n=3
Redim s (n,n)
i=1 j=n
s(i,j) =1
For K =1 To n*n-1
If i+1>n Then
i=n-j+2 j=1
Else if i+1<=n and j+1>n then
j=j-i i=1
else i=i+1 j=j+1
end if
s(i,j)=k
next k
for i =1 to n
for j=1 to n
prints(i,j)
next j
next i
end sub
帮我点播一下 只要懂 可以加分啊 展开
3个回答
展开全部
Option Base 1
Private Sub Command1_Click()
Dim s() As Integer
Dim k As Integer, n As Integer
n = 3
ReDim s(n, n)
i = 1: j = n
s(i, j) = 1
For k = 1 To n * n - 1
If i + 1 > n Then
i = n - j + 2: j = 1
ElseIf i + 1 <= n And j + 1 > n Then
j = j - i: i = 1
Else
i = i + 1: j = j + 1
End If
s(i, j) = k
Next k
For i = 1 To n
For j = 1 To n
Print s(i, j),
Next j
Next i
End Sub
运行结果:
展开全部
For k = 1 To n * n - 1
If i + 1 > n Then
i = n - j + 2: j = 1
ElseIf i + 1 <= n And j + 1 > n Then
j = j - i: i = 1
Else
i = i + 1: j = j + 1
End If
s(i, j) = k
Next k
这一部分是最重要的
当k=1,i=1,j=3 执行 ElseIf i + 1 <= n And j + 1 > n Then
j = j - i: i = 1
j=2,i=1 s(i2)=1
当k=2 i =1,j=2 执行Else
i = i + 1: j = j + 1
i=2,j=3 s(2,3)=2
当k=3 i=2,j=3 执行ElseIf i + 1 <= n And j + 1 > n Then
j = j - i: i = 1
j=1,i=1
s(1,1)=3
当k=4 i=1,j=1 执行Else
i = i + 1: j = j + 1
i=2,j=2 s(2,2)=4
楼主剩下的自己算吧 一直算到k=8 ,for循环结束,数组s(3,3)总共有9个数
不懂可追问 谢谢
If i + 1 > n Then
i = n - j + 2: j = 1
ElseIf i + 1 <= n And j + 1 > n Then
j = j - i: i = 1
Else
i = i + 1: j = j + 1
End If
s(i, j) = k
Next k
这一部分是最重要的
当k=1,i=1,j=3 执行 ElseIf i + 1 <= n And j + 1 > n Then
j = j - i: i = 1
j=2,i=1 s(i2)=1
当k=2 i =1,j=2 执行Else
i = i + 1: j = j + 1
i=2,j=3 s(2,3)=2
当k=3 i=2,j=3 执行ElseIf i + 1 <= n And j + 1 > n Then
j = j - i: i = 1
j=1,i=1
s(1,1)=3
当k=4 i=1,j=1 执行Else
i = i + 1: j = j + 1
i=2,j=2 s(2,2)=4
楼主剩下的自己算吧 一直算到k=8 ,for循环结束,数组s(3,3)总共有9个数
不懂可追问 谢谢
追问
我好像应该懂了- -谢了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim k As Integer, n As Integer
n = 3
ReDim s(n, n)
i = 1
j = n
s(i, j) = 1
For k = 1 To n * n - 1
If i + 1 > n Then
i = n - j + 2
j = 1
ElseIf i + 1 <= n And j + 1 > n Then
j = j - i
i = 1
Else
i = i + 1
j = j + 1
End If
s(i, j) = k
Next k
For i = 1 To n
For j = 1 To n
Debug.Print i, j
Next j
Print
Next i
End Sub
Dim k As Integer, n As Integer
n = 3
ReDim s(n, n)
i = 1
j = n
s(i, j) = 1
For k = 1 To n * n - 1
If i + 1 > n Then
i = n - j + 2
j = 1
ElseIf i + 1 <= n And j + 1 > n Then
j = j - i
i = 1
Else
i = i + 1
j = j + 1
End If
s(i, j) = k
Next k
For i = 1 To n
For j = 1 To n
Debug.Print i, j
Next j
Next i
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询