单选题
VB
题号 #2273194
在窗体上面1个名称为Command1的命令按钮,然后编写下列事件过程
Option Base 1
Private Sub,Command1 Click( )
Dim a(5,5)ks Integer
For i=1 To j
For j=1 To 5
a(i,j)=(i+j)*5\10
Next j
Next i
S=0
For i=1 To j
s=s+a(i,i)
Next i
Print s
End Sub
程序运行后,单击命令按钮,输出结果是( )。
参考答案
A
答案解析
A。【解析】程序首先是利用两层For循环给数组进行赋值,其规律是:第一行,a(1,1)=1,a(1,2) =1,a(1,3)=2,a(1,4)=2,a(1,5)=3;第二行,a(2,1)=1,a(2,2)=2,a(2,3)=2,a(2,4)=3,a(2,5) =3;第三行,a(3,1)=2,a(3,2)=2,a(3,3)=3,a(3,4)=3,a(3,5)=4;……第五行,a(5,1)=3,a(5,2) =3,a(5,3)=4,a(5,4)=4,a(5,5)=5。可知正对角线上的是1、2、3、4、5。题中的S就是计算正对角线上的和。故应选择A。
你可能感兴趣的试题
A.Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii==13 Then
'回车符的ASCIl码是13
a=Val(Text1)
If a>=0 Or a<=100 Then
Text2.SetFocus
Else
Text1.SetFocus:MsgBox("分数错")
End If
End If
End Sub
If KeyAscii==13 Then
'回车符的ASCIl码是13
a=Val(Text1)
If a>=0 Or a<=100 Then
Text2.SetFocus
Else
Text1.SetFocus:MsgBox("分数错")
End If
End If
End Sub
B.Private Sub Textl—KeyPress(KeyAscii As Integer)
If KeyAseii=13 Then
'回车符的ASCIl码是13
a=Val(Text1)
If a>=0 And a<=100 Then
Textl.SetFocus
Else
Text2.SetFocus:MsgBox("分数错")
End If
End If
End Sub
If KeyAseii=13 Then
'回车符的ASCIl码是13
a=Val(Text1)
If a>=0 And a<=100 Then
Textl.SetFocus
Else
Text2.SetFocus:MsgBox("分数错")
End If
End If
End Sub
C.Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii=13 Then
'回车符的ASCII码是13
a=Val(Text1)
If a<0 And a>100 Then
Text2.SetFocus
Else
Text1.SetFocus:MsgBox("分数错")
End If
End If
End Sub
If KeyAscii=13 Then
'回车符的ASCII码是13
a=Val(Text1)
If a<0 And a>100 Then
Text2.SetFocus
Else
Text1.SetFocus:MsgBox("分数错")
End If
End If
End Sub
D.Private Sub Text1_KeyPress(KeyAscii As Integer)
If KevAscii=13 Then
'回车符的ASCII码是13
a=Val(Textl)
If a>=0 Aad a<=100 Then
Text2.SetFocus
Else
Text1.SetFocus:MsgBox("分数错")
End If
End If
End Sub
If KevAscii=13 Then
'回车符的ASCII码是13
a=Val(Textl)
If a>=0 Aad a<=100 Then
Text2.SetFocus
Else
Text1.SetFocus:MsgBox("分数错")
End If
End If
End Sub
A.计算矩阵外围一圈元素的累加和
B.计算矩阵除外围一圈以外的所有元素的累加和
C.计算矩阵第1列和最后一列元素的累加和
D.计算矩阵第1行和最后一行元素的累加和
