试题

试题 试卷

logo

题型:单选题 题类:常考题 难易度:普通

浙江省诸暨市牌头中学2017-2018学年高二下学期信息技术第一次月考试题

有如下Visual Basic程序:

Private Sub Command1_Click()

Dim sum As Double, x As Double

sum = 0

n = 0

For i = 1 To 5

x = n / i

n = n + 1

sum = sum + x

Next i

End Sub

该程序通过For循环计算一个表达式的值,这个表达式是(   )

A、1+1/2+2/3+3/4+4/5 B、1+1/2+2/3+3/4    C、1/2+2/3+3/4+4/5 D、1+1/2+1/3+1/4+1/5
举一反三
编写VB程序,功能为:单击“发牌”按钮“Command1”后,从一副扑克牌(不包括大王、小王、J、Q、K、A)中随机抽取5张牌,牌的花色(♠♥♣♦)忽略,显示在列表框“List1”中。如果这5张牌由一个对子和一个顺子(3张牌连续)组成,则在标签“Label1”中显示“运气不错:)”,否则显示“运气一般:|”。程序运行界面如图所示。

实现上述功能的VB程序如下:

Private Sub Command1_Click()

  List1.Clear

  Dim five(1 To 5) As Integer

  Dim i As Integer, j As Integer, k As Integer

  Dim p As Integer, find_pair As Boolean

  '随机抽取5张牌,将牌的点数存储在数组five中,并在List1中显示。代码略

  i = 5: p = 1: find_pair = False

  Do While i>= 2

    j=p

    Do While j <= i - 1

      If five(j) > five(j + 1) Then

        t = five(j): five(j) = five(j + 1): five(j + 1) = t

      ElseIf five(j) = five(j + 1) And Not find_pair Then

        t = five(1): five(1) = five(j): five(j) = t

        t = five(2): five(2) = five(j + 1): five(j + 1) = t

        find_pair = True

        i = i + 1

        p = _____________

        Exit Do

      End If

      j = j + 1

    Loop 

    i = i - 1

  Loop

  k = 0

  For i = 3 To 4

    If  Then k = k + 1

  Next i

  If five(1) = five(2) And k = 2 Then

    Label1.Caption = "运气不错:)"

  Else

    Label1.Caption = "运气一般:|"

  End If

End Sub

请回答下列问题:

返回首页

试题篮