单选题 VB
题号 #2536767

在窗体上面1个名称为Co mmand1的命令按钮,然后编写下列事件过程
Option Base 1
Private Sub Co mmand1_Click()
Di ma(5,5)As Integer
For i =1To 5 For j=1To 5
a(i ,j)=(i +j )*5\10
Next j
Next i
s =0
For i =1To 5
s =s +a(i ,i)
Next i
Print s
End Sub
程序运行后,单击命令按钮,输出结果是(  )。

进入在线模考

参考答案

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 =13Then
回车符的ASCII 码是13
a=Val(Text1)
If a >=0Or a <=100Then
Text2 . SetFocus
Else
Text1 . SetFocus :MsgBox ("分数错")
End If
End If
End Sub
B.Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii =13Then 回车符的ASCII 码是13
a=Val(Text1)
If a >=0And a <=100Then
Text1 . SetFocus
Else
Text2 . SetFocus :MsgBox ("分数错")
End If
End If
End Sub
C.Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii =13Then 回车符的ASCII 码是13
a=Val(Text1)
If a <0And a >100Then
Text2 . SetFocus
Else
Text1 . SetFocus :MsgBox ("分数错")
End If
End If
End Sub
D.Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii =13Then 回车符的ASCII 码是13
a=Val(Text1)
If a >=0And a <=100Then
Text2.SetFocus
Else
Text1.SetFocus :MsgBox ("分数错")
End If
End If
End Sub
找试题 · 找答案 · 找资料 在线模考