最新VB程序改错40题含答案.doc
《最新VB程序改错40题含答案.doc》由会员分享,可在线阅读,更多相关《最新VB程序改错40题含答案.doc(179页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateVB程序改错40题含答案第2题 (1【程序改错】题目:该程序实现将输入的 0 - 255 之间的正整数转换成二进制数Option ExplicitPrivate Sub Form_Click() Const n = 8 Dim a(n) As Integer, s As String, m As Integer, x As Integer x = Val(InputB
2、ox(请输入一个 0 - 255 之间的正整数:) Print x For m = 1 To n a(m) = x Mod 2 x = x / 2 Next m s = For m = n To 0 Step -1 s = Str(a(m) Next m Print s End Sub答案:=(答案1)=For m = 0 To n=(答案2)=x= x 2=或=x= int(x/2)=(答案3)=s = s + Str(a(m)第3题 (1.0分) 题号:463【程序改错】题目:以下程序功能是输入三个数,由大到小排序。Option ExplicitDim A As IntegerDim B
3、As IntegerDim C As IntegerPrivate Sub Form_Click() Dim nTemp As Integer A = Val(InputBox(Please input first integer, 输入正整数) B = Val(InputBox(Please input second integer, 输入正整数) C = Val(InputBox(Please input third integer, 输入正整数) If A = C Then nTemp = A A = B B = nTemp End If If B = C Then nTemp = A
4、A = C C = nTemp End If If A = B Then nTemp = B B = C C = nTemp End If Print The integers in order is; A; B; CEnd Sub答案:=(答案1)=If A = A Then=(答案2)=If A = A Then=(答案3)=If B = B Then第4题 (1.0分) 题号:127【程序改错】题目:下面程序可输出如下图形: * * * * *-Option ExplicitPrivate Sub Form_Click()Dim m As Integer, n As Integer, s
5、 As String, i As Integer, j As Integern = 4m = 1s = *For i = 5 To 1 Step -1 Print Spc(n) For j = 1 To 2 * m - 1 Print s; Next j Print n = n + 1 m = m - 1Next iEnd Sub答案:=(答案1)=Print Spc(n);=或=Print Spc(i);=或=? Spc(n);=或=? Spc(i);=(答案2)=n = n - 1=或=n = - 1+n=(答案3)=m = m + 1第5题 (1.0分) 题号:469【程序改错】题目:已
6、知一个函数f(x)=1000*sin(x),利用绘图方法 在图片框中显示其图形。结果如图1Option ExplicitPrivate Const pi = 3.14159Private Sub Command1_Click() Dim x As Integer Picture1.Scale (-pi, -1200)-(pi, 1200) For x = -pi To pi Step pi Picture1.PSet (x, 1000 * pi * Sin(x), vbRed Next xEnd Sub答案:=(答案1)=Dim x As Single=或=Dim x!=(答案2)=For x
7、 = -pi To pi Step pi / 180=(答案3)=Picture1.PSet (x, 1000 * Sin(x), vbRed=或=Picture1.PSet (x, Sin(x)*1000), vbRed第6题 (1.0分) 题号:497【程序改错】题目:编程求一个十进制整数n的各位数字之和,设n为小于或等于5位的数。Option ExplicitPrivate Sub Form_Click() Dim N As Integer, Sum As Integer, S1 As String, S2 As String Dim i As Integer, Ch As String
8、 Sum = 0 N = InputBox(输入整数n) S1 = Str(N) S1 = RTrim(S1) For i = 1 To Len(S1) Ch = Mid(N, i, 1) Sum = Val(Ch) Next i Print 该整数的各位数之和是:; SumEnd Sub答案:=(答案1)=S1 = Trim(S1)=或=S1 = lTrim(S1)=(答案2)=Ch = Mid(S1, i, 1)=(答案3)=Sum = Sum + Val(Ch)=或=Sum = Sum + Val(Ch)第7题 (1.0分) 题号:454【程序改错】题目:本程序的功能是随机产生的10个两
9、位正整数,并进行递减排序。Option ExplicitPrivate Sub CreateRND() Dim Temp As Integer Dim I As Integer Dim N As Integer Dim X(10) As Integer Dim J As Integer N = 10 Print 数据: For I = 1 To N X(I) = Int(Rnd() * 90) Print X(I); Next I Print Print 排序: For I = 0 To N - 1 For J = I + 1 To N If X(I) X(J) Then Temp = X(I
10、) X(J) = X(I) X(I) = Temp End If Next J Print X(I); Next I PrintEnd SubPrivate Sub Command1_Click() CreateRNDEnd Sub答案:=(答案1)=X(I) = Int(10 + Rnd() * 90)=或=X(I) = Int(10 + Rnd() * 90)=(答案2)=If X(I) X(J) Then=或=If X(I) X(I) Then=或=If X(J) = X(I) Then=(答案3)=temp = X(J)第9题 (1.0分) 题号:130【程序改错】题目:以下程序段用于
11、计算5的N次方。Option ExplicitPrivate Sub Form_Click() Dim n As Integer, k As Integer, s As Long n = InputBox( Input n ) k = 0 s = 0 Do While k = n s = s * 5 k = k + 1 Next Print 5的; n次方是; sEnd Sub答案:=(答案1)=k=1=(答案2)=s=1=(答案3)=Loop第11题 (1.0分) 题号:452【程序改错】题目:用自定义函数的方法求sum(x),求当-1x1时, sum(x)=x/2!+x2/3!+x3/4!
12、+xn/(n+1)!, 当x1或x-1时,函数值为0。当n=0时,输入数 据错误。X、N都是由用户输入。Option ExplicitPrivate Sub Command1_Click() Dim s As Single Dim n As Integer, x As Single, k As Integer n = Val(InputBox(Please input a integer value:) x = Val(InputBox(Please input a single value:) If n 1 Or x 0 Then pjf = pjf / 30 Debug.Print 不及格
13、 + Str$(bjg) + 人,及格 + Str$(jg) + 人,中等 + Str$(zd) + 人; Debug.Print 良好 + Str$(lh) + 优秀 + Str$(yx) + 人 Debug.Print 优秀分数段成绩平均分 & pjfEnd Sub答案:=(答案1)=a = Int( Rnd() * 100)=或=a = Int( Rnd * 100)=(答案2)=pjf = pjf + a=(答案3)=If yx 0 Then pjf = pjf / yx第17题 (1.0分) 题号:456【程序改错】题目:挑选单数并排序程序:程序启动后由计算机自动产 生20个属于10
14、0,300之间的随机整数,单击显 示全体按钮时,在Form1上显示这20个随机数; 单击显示奇数按钮时,在Form1上显示其中的奇数; 单击排序按钮时,在Form1上将这些奇数从小到大显示。 要求显示格式为每行显示5个数据。Option ExplicitPrivate a(20) As Integer, b(20) As IntegerPrivate k As IntegerPrivate Sub cmdodd_Click()Dim I As Integerk = 0For I = 1 To 20 If a(I) / 2 = Int(a(I) / 2) Then k = k + 1 b(k)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 最新 VB 程序 改错 40 答案
限制150内