• 2021-04-14
    以下程序段运行的结果是______。 Dima(-1 To 5)As Boolean Dim flag As Boolean flag=False Dim i As Integer Dim j As Integer Do Until flag=True For i=-1 To 5 j=j+1 If a(i)=False Then a(i)=True Exit For End If If i=5 Then flag=True End If Next Loop Print j A.20 B.7 C.35 D.8
  • 正确答案:C解析:该程序段的作用是给数组a的每个数组元素赋值True,具体实现的方式为:每次从数组a的第一个元素开始判断,该元素是否为False,如果是,则令此元素为True,然后跳出循环,重新从数组a的第一个元素开始判断:如果当前元素不为False,则判断下一个元素。因此语句j=j+1将执行.1+2+3+4+5+6+7=28次,即j=28。然后再遍历一遍数组a的所有元素,最后结束程序段。所以j最终的值是: j=28+7=35

    内容

    • 0

      下面程序运行后,语句“Print i”执行的次数是( )。 Private Sub Form_Click() Dim i As Integer,j As Integer i=0 Do i=i+1 Forj=10 To 1 Step-3 i=i+j Print i Next j Loop While i<50 End Sub A: 4 B: 8 C: 12 D: 16

    • 1

      以下程序的运行结果是 Sub s1(b() As Integer) For i = 1 To 4 b(i) = 2 * i Next i End Sub Private Sub Command1_Click() Dim a(1 To 4) As Integer For i = 1 To 4 a(i) = i + 5 Next i s1 a() For i = 1 To 4 Print a(i) Next i End Sub

    • 2

      运行下面的程序,第二行显示结果是___________。 Private Sub Form_Click() Dim A As Integer Dim i As Integer A = 5 For i = 1 To 9 Call sub1(i, A) Print i, A Next i End Sub Private Sub sub1(x As Integer, y As Integer) Static N As Integer Dim I As Integer For I = 3 To 1 Step -1 N = N + x x = x + 2 Next I y = y + N End Sub

    • 3

      执行以下程序,单击命令按钮后,输出结果是______。 Private Sub Command1_Click() Dim a(5) As Integer Dim b For i = 1 To 5 a(i) = i*i Next i For Each b In a Print b; Next b End Sub

    • 4

      判断一个数是否为素数。并显示相应提示。如:该数为素数时,显示"素数";该数为非素数时,显示"非素数"。要求使用For语句来实现,用布尔型变量flag作为该数是否为素数的标志,注意:不得使用Goto语句. Private Sub Command1_Click() Dim flag As Boolean , m As Integer m = Val(InputBox("n:")) flag = True For i = 2 To m - 1 If m Mod i = 0 Then 【1】 : Exit For Next i If flag = True Then Print "素数" Else Print "非素数" End If End Sub