VB程序改错40题.doc
《VB程序改错40题.doc》由会员分享,可在线阅读,更多相关《VB程序改错40题.doc(69页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateVB程序改错40题第2题 (1第57题 (1.0分) 题号:465-【程序改错】-题目:用InputBox函数输入一个字符串,编写程序按与 输入的字符相反的次序用Msgbox函数输出这个字 符串。如输入字符串为abcdefgh,则输出为h gfedcba,输出效果如图1。-Option ExplicitPrivate Sub Command1_Click() Dim
2、pristr As String, outstr As String Dim i As Integer pristr = InputBox(please input a string) *FOUND* For i = 0 To Len(pristr) *FOUND* outstr = outstr + Mid(pristr, Len(pristr) - i) Next i *FOUND* MsgBox outstr, , The Output Result End Sub答案:=(答案1)=For i = 0 To Len(pristr) - 1=或=For i = 0 To -1+Len(p
3、ristr)=(答案2)=outstr = outstr + Mid(pristr, Len(pristr) - i, 1)=或=outstr = Mid(pristr, Len(pristr) - i, 1)+outstr=(答案3)=MsgBox outstr, vbQuestion, The Output Result 第59题 (1.0分) 题号:147-【程序改错】-题目:下面的程序用来产生并输出图示的杨辉三角。 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1-Option ExplicitPublic Sub readin(a() As In
4、teger, n As Integer) Dim i, j As Integer For i = 1 To n*FOUND* a(i, n) = 1 a(i, 1) = 1 Next i For i = 3 To n*FOUND* For j = 2 To n a(i, j) = a(i - 1, j) + a(i - 1, j - 1) Next j Next iEnd SubPublic Sub printf(a() As Integer, n As Integer) Dim i, j As Integer For i = 1 To n*FOUND* For j = 1 To n Prin
5、t Tab(5 * j + 10); a(i, j); Next j Print Next i PrintEnd SubPrivate Sub Form_Click() Dim x(10, 10) As Integer Call readin(x(), 6) Call printf(x(), 6)End Sub答案:=(答案1)=a(i, i) = 1=(答案2)=For j = 2 To i - 1=或=For j = 2 To -1 + i=(答案3)=For j = 1 To i第60题 (1.0分) 题号:146-【程序改错】-题目:用辗转相除法求两个整数的最大公约数。-Option
6、ExplicitFunction gcd(ByVal m As Integer, ByVal n As Integer) As Integer Dim r As Integer r = m Mod n Do While r 0*FOUND* n = m n = r r = m Mod n Loop*FOUND* gcd = rEnd FunctionPrivate Sub Form_Click() Dim a As Integer, b As Integer, c As Integer a = InputBox(输入一个整数) b = InputBox(输入一个整数) a = Val(a) b
7、 = Val(b)*FOUND* Call gcd(a, b) Print a, b, cEnd Sub答案:=(答案1)=m = n=(答案2)=gcd = n=(答案3)=c = gcd(a, b)第65题 (1.0分) 题号:492-【程序改错】-题目:输入两个正整数m和n,求其最大公约数。-Option ExplicitPrivate Sub Form_Click() Dim m As Integer, n As Integer, r As Integer m = InputBox(输入m的值:) n = InputBox(输入n的值:) Do While n 0 *FOUND* r
8、= m / n m = n *FOUND* n = m Loop *FOUND* Print 两数的最大公因子为:; nEnd Sub答案:=(答案1)=r = m Mod n=(答案2)=n = r=(答案3)=Print 两数的最大公因子为:; m第66题 (1.0分) 题号:467-【程序改错】-题目:从计算机输入三个数 , 找出中间数-Option ExplicitPrivate Sub FindMidNum() Dim x As Integer, y As Integer, z As Integer, A As Integer x = InputBox(PLEASE INPUT TH
9、E FIRST NUMBER) y = InputBox(PLEASE INPUT THE SECOND NUMBER) z = InputBox(PLESSE INPUT THE THIRD NUMBER) *FOUND* If x y Then A = x x = y y = A End If *FOUND* If y = z Then Print y *FOUND* ElseIf x = z Then Print z Else Print x End IfEnd SubPrivate Sub Form_Click() FindMidNumEnd Sub答案:=(答案1)=If x x T
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VB 程序 改错 40
限制150内