1、1. 编写单击“计算”按钮事件过程,随机产生 10 个 50100 的整数,将其用冒泡排序法按升序排列后显示于窗体。Dim A(1 To 10) As IntegerRandomizeFor i = 1 To 10A(i) = Int(Rnd * 51 + 50)Label1.Caption = Label1.Caption ” ”;a(i)Next iFor i=1 to 9Imin=iFor j=i+1 to 10If a(j) x then max=a(i)Next iFor i=1 to 6Min=a(1)If a(i)min then min=a(i)S=s+a(i)Average=
2、s/6Next iPrint ;“最大值为 ”;maxPrint ;”最小值为 ”;minPrint ;”平均值为 ”;average 5. 求表达式1!+3!+5!+7!+的前n项之和。N的值通过调用Inputbox函数输入。Dim s#,i%,n%,t#T=1ClsN=inputbox(“输入项数N”,n)For i=1 to 2*n-1T=t*iIf I mod 2 =1 then s=s+tPrint “1!+3!+5!+7!+(2*n-1)!”;sNext i6. 求表达式1+1/(1+2 )+1/(2+3)+1/ (3+4)+前n项之和。Dim n%, i%, t#, s#Clsn
3、 = InputBox(“输入项数N“)For i = 1 To nt = 1 / (2 * i - 1)s = s + tNext iPrint “表达式1+1/(1+2)+1/(2+3)+的前“; n; “项和为:“; s7. 生成20个203000 之间的随机数,按每行5个输出这20个数据,再下行输出其中除5余2并被3整除的数,并求出它们的和。Dim a(1 To 20), i%, s!,t%RandomizeClsFor i = 1 To 20T=1+tIf t Mod 5 = 0 Then Printa(i) = Int(Rnd * 2981 + 20)Print ; a(i); “
4、;Next iPrintPrint “符合条件的数有:“;For i = 1 To 20If a(i) Mod 5 = 2 And a(i) Mod 3 = 0 Thens = s + a(i)t=t+1Print ; a(i); “End IfNext iPrint “其和为“; s8. 当单击“计算”按钮时,输出斐波那契数列的前16项。Private Sub Form_Click()a = 1: b = 1Picture1.Print a; Tab(15); bFor i = 2 To 8c = a + bd = b + cPicture1.Print c; Tab(15); da = c
5、b = dNext iEnd Sub9. 当单击“输出”按钮时,输出如下图形,当单击“清除”按钮时,把屏幕上输出的内容清除,当单击“结束”按钮时,结束程序的运行。* * * * * * * * * * * * * * * * * * * * * * * * * *Private Sub command1_Click() For i = 4 To 1 Step -1 print”*”Print” *” Print Tab(25 - i); print” *“For j = 1 To 7 print” *”Print “*“;Next jPrintNext iEnd SubPrivate Sub Command2_Click()ClsEnd SubPrivate Sub Command3_Click()EndEnd Sub10. 当单击“输出”按钮时,输出如下图形,当单击“清除”按钮时,把屏幕上输出的内容清除,当单击“结束”按钮时,结束程序的运行。* * * * * * * * * * * * * * * * * * * * * *Dim i%, j%ClsFor i = 5 To 1 Step -1Print Spc(25 - i);For j = 1 To 2 * i - 1Print “*“;Next jPrintNext i