1.执行下面程序,单击Commandl,则数组元素a(1,2)的数值是?a(2,3)的数值 是?a(4,3)的数值是?
OptionExplicitPrivateSubCommandl_Click()Dima(4,4)AsInteger,iAsIntegerDimjAsInteger,kA...
Option Explicit
Private Sub Commandl_Click()
Dim a(4,4)As Integer,i As Integer
Dim j As Integer,k As Integer,n As Integer
n=6:k=2
Do
For i=1 To 4
For j=1 To 4
If i+j=k Then
a(i,j)=n
n=n-1
End If
Next j
Next i
k=k+1
Loop Until k>8
For i=1 To 4
For j=1 To 4
print Right(“ “ & a(i,j),3);
Next j
Print
Next i
End Sub
帮忙解释一下吧,亲
自学的,不理解!!!
拜托啦!!!!!!!!!!
帮忙 展开
Private Sub Commandl_Click()
Dim a(4,4)As Integer,i As Integer
Dim j As Integer,k As Integer,n As Integer
n=6:k=2
Do
For i=1 To 4
For j=1 To 4
If i+j=k Then
a(i,j)=n
n=n-1
End If
Next j
Next i
k=k+1
Loop Until k>8
For i=1 To 4
For j=1 To 4
print Right(“ “ & a(i,j),3);
Next j
Next i
End Sub
帮忙解释一下吧,亲
自学的,不理解!!!
拜托啦!!!!!!!!!!
帮忙 展开
展开全部
首先,分析这段代码:
n = 6: k = 2
Do
For i = 1 To 4
For j = 1 To 4
If i + j = k Then
a(i, j) = n
n = n - 1
End If
Next j
Next i
k = k + 1
Loop Until k > 8
理解:
1, For i = 1 To 4
For j = 1 To 4
If i + j = k Then
a(i, j) = n
n = n - 1
End If
Next j
Next i
这个循环一周,并没有对16个数组元素全部赋值;
当:k=2的时候;
满足:i + j = k的,只有:i=1,j=1,即 a(1,1) = 6,并且注意到没完成1次对元素的赋值,n递减1
接下来一周,K加1=3
满足:i + j = 3的,有:a(1,2) = 5, a(2,1) = 4,
接下来一周,K加1=4
满足:i + j = 4的,有:a(1,3) = 3, a(2,2) = 2, a(3,1) = 1,
接下来一周,K加1=5
满足:i + j = 5的,有:a(1,4) = 0, a(2,3) = -1, a(3,2) = -2, a(4,1) = -3,
接下来一周,K加1=6
满足:i + j = 6的,有:a(2,4) = -4, a(3,3) = -5, a(4,2) = -6,
接下来一周,K加1=7
满足:i + j = 7的,有:a(3,4) = -7, a(4,3) = -8,
接下来一周,K加1=8
满足:i + j = 8的,有:a(4,4) = -9,
这样16个元素的值,都赋好了。
n = 6: k = 2
Do
For i = 1 To 4
For j = 1 To 4
If i + j = k Then
a(i, j) = n
n = n - 1
End If
Next j
Next i
k = k + 1
Loop Until k > 8
理解:
1, For i = 1 To 4
For j = 1 To 4
If i + j = k Then
a(i, j) = n
n = n - 1
End If
Next j
Next i
这个循环一周,并没有对16个数组元素全部赋值;
当:k=2的时候;
满足:i + j = k的,只有:i=1,j=1,即 a(1,1) = 6,并且注意到没完成1次对元素的赋值,n递减1
接下来一周,K加1=3
满足:i + j = 3的,有:a(1,2) = 5, a(2,1) = 4,
接下来一周,K加1=4
满足:i + j = 4的,有:a(1,3) = 3, a(2,2) = 2, a(3,1) = 1,
接下来一周,K加1=5
满足:i + j = 5的,有:a(1,4) = 0, a(2,3) = -1, a(3,2) = -2, a(4,1) = -3,
接下来一周,K加1=6
满足:i + j = 6的,有:a(2,4) = -4, a(3,3) = -5, a(4,2) = -6,
接下来一周,K加1=7
满足:i + j = 7的,有:a(3,4) = -7, a(4,3) = -8,
接下来一周,K加1=8
满足:i + j = 8的,有:a(4,4) = -9,
这样16个元素的值,都赋好了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询