试题

试题 试卷

logo

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

浙江省金华市江南中学2020届高三下学期信息技术4月初测试卷

有如下VB程序段:

Function GCD(m As Long, n As Long) As Long

 Dim temp As Long, r As Long

 If m < n Then temp = m: m = n: n = temp

 d = m - n

 Do While d <> n

  If d >= n Then

    m = d

  Else

    m = n

    n = d

  End If

  d = m - n

 Loop

 GCD = n

End Function

Private Sub Command1_Click()

  Text1.Text = Str(GCD(48,36))

End Sub

程序运行完后,单击Command1按钮,文本框Text1中显示的是 (  )

A、12 B、18 C、36 D、48
举一反三
下列VB程序实现数字字母混合序列分离后分别排序,最后又合并输出。具体算法如下:在文本框Text1输入若干组混合序列,每组序列中仅包含一组字母和一个多位数字,序列之间用逗号隔开,以逗号结束。单击“排序”按钮command1,把每组序列中的字母和数字分开,并分别排序,最后在列表框list1输出。排序规则如下:所有数字按从小到大升序排序,字母序列按长度升序排序,若长度相同,直接按字母序列大小升序排序(按字母的ASCII码排序,“A”<“Z”<“a”<“z”)。实现算法的部分程序界面如图所示,VB程序代码如下,回答下列问题:

Private Sub Command1_Click()

Dim a(1 To 6) As Integer, b(1 To 6) As String, i as integer, j as integer

Dim c As String, k As Integer, tmp1 As Integer, tmp2 As String

s=text1.text

i = 1: k = 1: tmp1 = 0: tmp2 = ""

Do While i <= Len(s)

      c = Mid(s, i, 1)

      If c = "," Then

         a(k) = tmp1: b(k) = tmp2

         tmp1 = 0: tmp2 = ""

              ①    

      Else

        If  Then 

           tmp2 = tmp2 + c

        Else

         tmp1=tmp1*10+val(c)

        End If

      End If

      i = i + 1

    Loop

    For i = 1 To 5

      For j = 1 To 6 - i

        If a(j) > a(j + 1) Then tmp1 = a(j): a(j) = a(j + 1): a(j + 1) = tmp1

    If Len(b(j)) > Len(b(j + 1)) Or      ②       Then

          tmp2 = b(j): b(j) = b(j + 1): b(j + 1) = tmp2

        End If

      Next j

    Next i

    For i = 1 To 6

      List1.AddItem Str(a(i)) + b(i)

    Next i

    End Sub

返回首页

试题篮