End Sub
2. 编写一个求最大公约数的函数,并调用该函数,程序如下: Function gcd(ByVal a As Integer,ByVal b As Integer) As Integer Dim re as integer Do While b<>0 re=a mod b a=b b=re Loop gcd=a End Function
Sub Command1_Click()
Dim x As Integer,y As Integer, z As integer X=96 Y=64
_z=gcd(x,y)_____ Print “结果=”;z End Sub
3. 请用正确的内容填空。以下程序找出50以内所有能构成直角三角形的整数组。 Private Sub Form_Click() For x=1 To 50 For y=x To 50 z=Sqr(x*x+y*y)
If ___ z<=5 And z=Int(z) ___ Then Print x; y; z Next y Next x Print End Sub
4. 执行下面的程序段后,s的值为__7__________ Private Sub Form_Click() Static s As Integer s = 5
For I = 1.4 To 2.1 Step 0.6 s = s + 1 Next I Print s End Sub
5. 执行下面的程序段后,X的值为_______8______。 X=5
For I=1 to 10 Step 2 X=X+I\\5 Next I
6. 函数odd用于判断一个数是否是奇数。当单击命令按钮时,产生 [1,9]之间的随机数,调用odd过程,判断该数是否为奇数。
如果是则显示“奇数”,否则显示“偶数”。 Private Sub odd(n As Integer) Print n; If n/2<>n\\2 Then Print \奇数\ Else
__Print “偶数”____ End If End Sub
Private Sub Command1_Click() Dim x As Integer Randomize
x =_ int(9*rnd+1) _____ odd x End Sub
7. 下列程序允许用户按Enter键将一个组合框(cboComputer)中没有的项目添加到组合框中。 Sub cboComputer_KeyPress(KeyAscii As Integer) Dim flag As Boolean If KeyAscii=13 Then flag=False
For I=0 To cboComputer.ListCount-1
If_cboComputer.Text=cboComputer.List(i)__Then Flag=True Exit For End If Next
If Not flag Then
_cboComputer.AddItem cboComputer.Text__ Else
MsgBox(”组合框中已有该项目!”) End If End If End Sub
8. 请用正确的内容填空。下面程序用“选择”法将数组a中的10个整数按升序排列。 Option Base 1
Private Sub Form_Click() Dim a
a = Array(678, 45, 324, 528, 439, 387, 87, 875, 273, 823) For I=1 To 9
For j= __i+1____ To 10 If ___a(i)>a(j)___Then t=a(I): a(I)=a(j): a(j)=t End If Next j
Next I For I=1 To 10 Print a(I); Next I End Sub
9. 以下程序的功能是:生成20个200到300之间的随机整数, 输出数的位置能被5整除的数并求出它们的和。请填空。 Private Sub Commandl_C1ick() For I=1 To 20
x=Int( ___Rnd___*200+100) If I Mod 5 =0 Then Print x S=S+ _x_____ End If Next I
Print \=\ End Sub
10. 以下程序的功能是:从键盘上输入若干个学生的考试分数, 统计并输出最高分数和最低分数,当输入负数时结束输入, 输出结果,请将程序补充完整。 Private Sub Form_Click() Dim x, amax, amin A Single x = InputBox(\ amax = x amin = x
Do While ___x>0_________ If x > amax Then amax = x End If
If __x
x = InputBox(\ Loop
Print \ End Sub