资源预览内容
第1页 / 共52页
第2页 / 共52页
第3页 / 共52页
第4页 / 共52页
第5页 / 共52页
第6页 / 共52页
第7页 / 共52页
第8页 / 共52页
第9页 / 共52页
第10页 / 共52页
亲,该文档总共52页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
以下程序的功能如图。Private Sub Form_Click()Dim a%, b%, c%, d!Dim x1, x2Dim p, q, ra = InputBox(请输入 a 的值)b = InputBox(请输入 b 的值)c = InputBox(请输入 c 的值)d = b * b - 4 * a * cp = -b / (2 * a)If d = 0 Then*SPACE*If【?】 Thenr = Sqr(d) / (2 * a)x1 = p + rx2 = p - rElsex1 = px2 = p*SPACE*【?】Print x1=; x1, x2=; x2*SPACE*【?】q = Sqr(-d) / (2 * a)Print x1=; p; +; q; i, x2=; p; -; q; iEnd IfEnd Sub答 案1 d 0 或 0 Max3 row = I 以下程序段用于实现矩阵转置,即将一个 nm 的矩阵的行和列互换Private Sub Form_Click()Const n = 3Const m = 4Dim a(n, m) As Integer, b(m, m) As IntegerFor I = 1 To nFor j = 1 To ma(I, j) = Int(Rnd * 90) + 10Next j*SPACE*【?】For I = 1 To nFor j = 1 To m*SPACE*【?】Next jNext IPrint 矩阵转置前For I = 1 To nFor j = 1 To mPrint a(I, j);Next j*SPACE*【?】Next IPrint 矩阵转置后For I = 1 To mFor j = 1 To nPrint b(I, j);Next jPrintNext IEnd Sub答 案1 Next i 或 Next2 b(j, i) = a(i, j)3 print 或 form1.print 或 ? 以下程序段用于输出杨辉三角:结果样式如图Private Sub Form_Click()Const n = 10Dim arr(n, n) As IntegerFor I = 1 To narr(I, I) = 1*SPACE* 【?】Next IFor I = 3 To nFor j = 2 To I - 1*SPACE*arr(i, j) =【?】Next jNext IFor I = 1 To nFor j = 1 To I*SPACE*【?】Next jPrintNext IEnd Sub答 案1 arr(i, 1) = 12 arr(i - 1, j - 1) + arr(i - 1, j)3 Print arr(i, j); 或 form1.Print arr(i, j); 或 ? arr(i, j); 下面过程 max()用于求 3 个数中最大值,利用这个过程求 5 个数中最大值。Private Sub Form_Click()Print 5 个数 34、124、68、73、352 的最大值是:max1 = max(34, 124, 68)*SPACE*max1 =【?】Print max1End SubPublic Function max(ByVal a%, ByVal b%, ByVal c%)*SPACE*If 【?】 Thenm = aElsem = bEnd If*SPACE*If 【?】 Thenmax = mElsemax = cEnd IfEnd Function答 案1 max(max1, 73, 352)2 ab 或 b c 或 c I 下面的程序段用于实现以下功能:利用冒泡法将一组整数从小到大排序。Private Sub Form_Click()Const n = 15Dim a(1 To n) As Integer, work As BooleanDim i As Integer, j As Integer, x As IntegerRandomizeFor i = 1 To na(i) = Int(90 * Rnd) + 10Next iFor i = 1 To nPrint a(i);Next iPrint*SPACE*For i = n To 2 【 ?】work = TrueFor j = 1 To i - 1If a(j) a(j + 1) Thenx = a(j): a(j) = a(j + 1): a(j + 1) = x*SPACE*【?】End IfNext j*SPACE*If work Then 【?】Next iFor i = 1 To nPrint a(i);Next iEnd Sub答 案1 Step -12 work = False 或 work=03 Exit For 以下程序的功能如图。Private Sub Form_Click()Dim s As Single, m As Integer, p#s = 1For m = 1 To 10*SPACE*p=N(M)【?】s = s + 1 / pNext mPrint sEnd SubFunction n(k%)p = 1For m = 1 To k*SPACE*p =P*MNext m*SPACE*【?】N=PEnd Function答 案1 n(m)2 p * m3 n = p 下面的程序段用于求矩阵相乘 C=AB,设 A、B、C 分别为 mp、pn、mn 的矩阵。Private Sub Form_Click()Const m = 4, p = 3, n = 2Dim a(1 To m, 1 To p) As IntegerDim b(1 To p, 1 To n) As IntegerDim c(1 To m, 1 To n) As IntegerDim i As Integer, j As Integer, k As Integer, sum As IntegerFor i = 1 To mFor k = 1 To pa(i, k) = iNext kNext iFor i = 1 To pFor k = 1 To nb(i, k) = iNext kNext iFor i = 1 To mFor j = 1 To n*SPACE*【?】For k = 1 To p*SPACE*sum = sum +【? 】Next k*SPACE*c(i, j) =【? 】Next j, iPrint 输出矩阵For i = 1 To mFor k = 1 To nPrint c(i, k),Next kPrintNext iEnd Sub答 案1 sum = 02 a(i, k) * b(k, j)3 sum 从键盘输入学生分数,统计学生总人数和各分数段人数,即优秀(90-100) 、良好(80-89) 、中等(70-79) 、及格(60-69) 、不及格(60 以下)的人数。Private Sub Form_Click()Dim score%, n1%, n2%, n3%, n4%, n5%msg = 请输入分数(-1 结束) msgtitile = 输入数据score = Val(InputBox(msg, msgtitle)*SPACE*While 【?】total = total + 1*SPACE* Select Case 【? 】Case Is = 90n1 = n1 + 1Case Is = 80n2 = n2 + 1Case Is = 70n3 = n3 + 1Case Is = 60n4 = n4 + 1Case Elsen5 = n5 + 1*SPACE*【?】score = Val(InputBox(msg, msgtitle)WendPrint n1, n2, n3, n4, n5,totalEnd Sub答 案1 score =0 And score =score 或 score =0 And 100=score2 score3 End Select 以下程序段用于实现:输入两个正整数 m 和 n,求其最大公因数和最小公倍数。-Private Sub Form_Click()Dim a%, b%, num1%, num2%, tempnum1 = InputBox(请输入一个正整数)num2 = InputBox(请输入一个正整数)*SPACE*If 【?】 Thentemp = num1: num1 = num2: num2 = tempEnd Ifa = num1b = num2*SPACE*Do While 【?】temp = a Mod ba = b*SPACE* 【?】LoopPrint 最大公因数为:; aPrint 最小公倍数为:; num1 * num2 / aEnd Sub答 案1 num1 num12 b 0 或 0 ? 或 not ch = ?2 A To Z3 Loop 下面的程序段用于建立文件并输出文件,文件内容如下:* * * * *Private Sub Form_Click()*SPACE*Open c:1.txt For 【?】 As #1For i = 1 To 5Print #1, Spc(i); *Next i*SPACE*【?】*SPACE*Open c:1.txt For 【?】 As #1For i = 1 To 5Line Input #1, xPrint xNext iClose #1End Sub答 案1 Output2 Close #1 或 Close 3 Input 下面的程序段用于打印出以下图形*
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号