版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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(InputBox("请输入一个 0 - 255 之间的正整数:") Print x For m = 1 To n a(m) = x Mod 2 x = x / 2 Next m s = " " For m = n
2、 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 As IntegerDim C As IntegerPrivate Sub Form_Click() Dim nTemp As Integer A = Val(Inpu
3、tBox("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 A =
4、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 <= B Then=或=If B >= A Then=(答案2)=If A <= C Then=或=If C >= A Then=(答案3)=If B <= C Then=或=If C >= B Then第4题 (1.0分) 题号:127'【程序改错】'题目:下面
5、程序可输出如下图形:' *' *' *' *' *'-Option ExplicitPrivate Sub Form_Click()Dim m As Integer, n As Integer, s 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 Su
6、b答案:=(答案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'【程序改错】'题目:已知一个函数f(x)=1000*sin(x),利用绘图方法' 在图片框中显示其图形。结果如图1Option ExplicitPrivate Const pi = 3.14159Private Sub Command1_Click() Dim x As Integer Picture1.Scale (-p
7、i, -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 = -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'【程序改错】'题目:编程求
8、一个十进制整数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 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 "
9、该整数的各位数之和是:" 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个两位正整数,并进行递减排序。Option ExplicitPrivate Sub CreateRND() Dim Temp As Integer Dim I As Integer Dim N As Integer D
10、im 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) X(J) = X(I) X(I) = Temp End If Next J Print X(I); Next I PrintEnd SubPrivate
11、 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(J) Then=或=If X(J) > X(I) Then=或=If X(J) >= X(I) Then=(答案3)=temp = X(J)第9题 (1.0分) 题号:130'【程序改错】'题目:以下程序段用于计算5的N次方。Option ExplicitPriva
12、te 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时,'
13、; sum(x)=x/2!+x2/3!+x3/4!+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 valu
14、e:") If n <= 0 Then k = MsgBox("数据输入错误!", vbRetryCancel + vbExclamation, "数据输入") Exit Sub End If s = Sum(x, n) Print sEnd SubFunction Sum(x As Single, n As Integer) Dim i As Integer, ss As Long ss = 1 Sum = 0 If x > 1 Or x < -1 Then Exit Do Else For i = 2 To n ss =
15、ss * i Sum = x (i - 1) / ss Next i End IfEnd Function答案:=(答案1)=exit Function=(答案2)=For i = 2 To n + 1=或=For i = 2 To 1+n=(答案3)=sum = sum + x (i - 1) / ss第14题 (1.0分) 题号:136'【程序改错】'题目:程序功能为打印下列图形:' *' *' *' *' *'-Option ExplicitPrivate Sub Form_Click()ClsDim i As Intege
16、rDim j As IntegerFor i = 1 To 7 For j = 1 To 5 Print "*" LoopPrintNext iEnd Sub答案:=(答案1)=For i = 1 To 5=(答案2)=For j = 1 To i=(答案3)=Next j=或=Next第16题 (1.0分) 题号:461'【程序改错】'题目:产生30个小于100的成绩随机数,并统计出优、良' 、中等、及格、不及格数的个数,并计算出成绩属' 于优秀段的成绩平均分。Option ExplicitPrivate Sub Form_Click()
17、Dim k%, a%, bjg%, jg%, zd%, lh%, yx As Integer Dim pjf As Integer Randomize pjf = 0 For k = 1 To 30 a = Int(Rnd() Select Case a Case 0 To 59 bjg = bjg + 1 '不及格 Case 60 To 69 jg = jg + 1 '及格 Case 70 To 79 zd = zd + 1 '中等 Case 80 To 89 lh = lh + 1 '良好 Case 90 To 100 yx = yx + 1 '优秀
18、 pjf = pjf + 1 End Select Next k If yx > 0 Then pjf = pjf / 30 Debug.Print "不及格" + Str$(bjg) + "人,及格" + Str$(jg) + "人,中等" + Str$(zd) + "人" Debug.Print "良好" + Str$(lh) + "优秀" + Str$(yx) + "人" Debug.Print "优秀分数段成绩平均分" &
19、amp; 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个属于100,300之间的随机整数,单击"显' 示全体"按钮时,在Form1上显示这20个随机数;' 单击"显示奇数"按钮时,在Form1上显示其中的奇数
20、;' 单击"排序"按钮时,在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) = a(I) End IfNext IFor I = 1 To k Print b(I)
21、; If Int(I / 5) <> I / 5 Then PrintNext IPrintEnd SubPrivate Sub cmdAll_Click() Randomize Dim I As Integer For I = 1 To 20 a(I) = Int(Rnd() * 20 + 100) Print a(I), If Int(I / 5) = I / 5 Then Print Next I PrintEnd SubPrivate Sub cmdsort_Click() Dim I As Integer Dim J As Integer Dim Temp As Inte
22、ger For I = 1 To k - 1 For J = I To k If b(I) > b(J) Then Temp = b(I): b(I) = b(J): b(J) = Temp Next J Next I For I = 1 To k Print b(I); If Int(I / 5) = I / 5 Then Print Next IEnd Sub答案:=(答案1)=If a(I) / 2 <> Int(a(I) / 2) Then=或=If a(I) mod 2 <>0 Then=或=If 0<>a(I) mod 2 Then=或=I
23、f a(I) / 2 <> a(I) 2 Then=或=If int(a(I) / 2) <> a(I) / 2 Then=或=If a(I) 2 <> a(I)/2 Then=(答案2)=If Int(I / 5) = I / 5 Then Print=或=If I mod 5 = 0 Then Print=或=If 0 = I mod 5 Then Print=或=If I / 5= int(I / 5) Then Print=或=If I / 5= I 5 Then Print=或=If I 5= I/ 5 Then Print=(答案3)=a(I)
24、= Int(Rnd() * 200 + 100)第19题 (1.0分) 题号:499'【程序改错】'题目:编程将一个数从已经有序(设从小到大排序)的数组' 中删除,使数组还继续保持有序而且其余元素按照下' 标连续存放。Option ExplicitPrivate Sub Form_Click() Dim A() As Integer, N As Integer, Flag As Integer Dim i As Integer, X As Integer, P As Integer Flag = 0 N = InputBox("输入元素个数"
25、) Dim A(N) For i = 1 To N A(i) = InputBox("输入数组的第" & i & "个元素") Next i Print "删除某元素前的数组" For i = 1 To N Print A(i); Next iStart: X = InputBox("输入要删除的元素:") For i = 1 To N If X = A(i) Then P = i: Flag = 1 Next i If Flag = 0 Then MsgBox ("没有此元素"
26、): GoTo Start For i = P To N - 1 A(i + 1) = A(i) Next i N = N + 1 Print "删除元素后的数组:" For i = 1 To N Print A(i); Next iEnd Sub答案:=(答案1)=ReDim A(N)=(答案2)=A(i) = A(i + 1)=或=A(i) = A(1 + i)=(答案3)=N = N - 1第20题 (1.0分) 题号:139'【程序改错】'题目:随机产生并输出100以内大于50的20个整数,输' 出时每5个数一行。Option Explici
27、tPrivate Sub Form_Click()Randomize TimerDim i As Integer, ma As Integeri = 1Do Until i < 20 ma = Rnd() * 100 1 If ma > 50 Then Print ma; i = i + 1 If i 5 = 0 Then Print End IfEnd IfLoopEnd Sub答案:=(答案1)=i = 0=(答案2)=Do while i < 20=或=Do while 20 > i=或=Do while i <=19=或=Do while 19 >
28、=i=(答案3)=If i mod 5 = 0 Then第23题 (1.0分) 题号:474'【程序改错】'题目:程序功能为求解一元二次方程的实根,请修正程序中错误。Option ExplicitPrivate Sub Form_Load() Dim a!, b!, c!, root1#, root2#, work As Double a = Val(InputBox(" 请输入系数a的值") b = Val(InputBox(" 请输入系数b的值") c = Val(InputBox(" 请输入系数c的值") wor
29、k = b * 2 - 4 * a * c If work >= 0 And a <> 0 Then root1 = (Sqr(work) / (2 * a) root2 = (Sqr(work) / (2 * a) Debug.Print "有二个实根" + Str$(root1) + "," + Str$(root2) Else Debug.Print "无实根!" End IfEnd Sub答案:=(答案1)=work = b 2 - 4 * a * c=或=work = b *b - 4 * a * c=(答
30、案2)=root1 = (-b + Sqr(work) / (2 * a)=或=root1 = ( Sqr(work) -b ) / (2 * a)=或=root1 = (-b + Sqr(work) / ( a*2)=或=root1 = ( Sqr(work) -b ) / ( a*2)=(答案3)=root2 = (-b - Sqr(work) / (2 * a)=或=root2 = (- Sqr(work) - b) / (2 * a)=或=root2 = (-b - Sqr(work) / ( a*2)=或=root2 = (- Sqr(work) - b) / (a*2)第28题 (
31、1.0分) 题号:133'【程序改错】'题目:下面程序将10个整数从大到小排序Option ExplicitPrivate Sub Form_Click()Dim t%, m%, n%, w%Dim a(10) As IntegerFor m = 1 To 10 a(m) = Int(10 + Rnd() * 90) Print a(m); " "Next mPrintFor m = 1 To 9 t = m For n = 2 To 10 If a(t) > a(n) Then n = t Next n If t = m Then w = a(m)
32、a(m) = a(t) a(t) = w End IfNext mFor m = 1 To 10 Print a(m)Next mEnd Sub答案:=(答案1)=For n = m + 1 To 10=(答案2)=If a(t) <a(n) Then t = n=或=If a(n) >a(t) Then t = n=(答案3)=If t <> m Then=或=If not t = m Then=或=If not m = t Then第30题 (1.0分) 题号:480'【程序改错】'题目:下面函数的功能是:求变量s(s=a+aa+aaa+aaaa+)
33、' 的值。其中,a是一个0-9的数字,总共累加a项。' 例如,当a=3时,s=3+33+333 (共累加3项)。Option ExplicitPublic Function Calc(a As Integer) Dim s As Long Dim t As Long Dim i As Integer s = a t = 1 For i = 2 To a t = t + a s = s + t Next i Calc = s Print sEnd FunctionPrivate Sub Command1_Click() Dim i As Integer i = InputBox(
34、"请输入数字(0-9):") Calc call iEnd Sub答案:=(答案1)=t = a=(答案2)=t = t * 10 + a=或=t = t * 10 + a=或=t = t * 10 + a=(答案3)=Calc i=或=Call Calc(i)=或=Calc (i)第31题 (1.0分) 题号:489'-'【程序改错】'-'题目:给定三角形的三条边,计算三角形的面积。要求' 程序首先判断给定的三条边能否构成三角形。'-Option ExplicitPrivate Sub Form_Click() Dim a
35、As Single, b As Single, c As Single Dim s As Single, t As Singlestart: a = InputBox("输入1边长:") b = InputBox("输入2边长:") c = InputBox("输入3边长:") If a + b < c Or b + c < a Then MsgBox ("不能构成三角形,请重新输入个边") GoTo start End If t = (a + b) / 2 s = Sqr(t - a) * (t -
36、b) * (t - c) Print "该三角形的面积:" sEnd Sub答案:=(答案1)=If a + b < c Or b + c < a Or a + c < b Then=(答案2)=t = (a + b + c) / 2=或=t = (a + b + c ) / 2=(答案3)=s = Sqr(t * (t - a) * (t - b) * (t - c)=或=s = Sqr( t * (t - a) * (t - b) * (t - c) )第32题 (1.0分) 题号:475'-'【程序改错】'-'题目:本
37、程序求3100之间的所有素数(质数)并统计个数;' 同时将这些素数从小到大依次写入顺序文件c:dataout.txt;' 素数的个数显示在窗体Form1上。'-Option ExplicitPrivate Sub Command1_Click() Dim Count As Integer, Flag As Boolean Dim t1 As Integer, t2 As Integer Open "dataout.txt" For Input As #1 Count = 0 For t1 = 3 To 100 Flag = True For t2 =
38、 2 To Int(Sqr(t1) If t1 Mod t2 = 0 Then Flag = False Next t2 If Flag = False Then Count = Count + 1 Write #1, t2 End If Next t1 Form1.Print "素数个数" Count Close #1End Sub答案:=(答案1)=Open "dataout.txt" For Output As #1=或=Open "dataout.txt" For Output As 1=(答案2)=If Flag Then=
39、或=If Flag=true Then=(答案3)=Write #1, t1=或=Write 1, t1第33题 (1.0分) 题号:137'-'【程序改错】'-'题目:求s=72+102+132+832的值。'-Option ExplicitPrivate Sub Form_Click()ClsDim s As LongDim i As Integers = 1For i = 7 To 832s = s + iloop 30Print sEnd Sub答案:=(答案1)=s =0=(答案2)=For i = 7 To 832 step 30=(答案3)
40、=Next i=或=Next第35题 (1.0分) 题号:131'-'【程序改错】'-'题目:下面程序用于将十个数字从小到大排序'-Option ExplicitOption Base 1Private Sub Form_Click()ClsDim a(10) As IntegerDim i As Integer, j As Integer, temp As IntegerFor i = 0 To 10If i Mod 2 = 0 Then a(i) = i Else a(i) = -iPrint a(i);NextPrintFor i = 1 To 1
41、0For j = 1 To 10 - iIf a(j) < a(j + 1) Thentemp = a(j): a(j) = a(j + 1): a(j + 1) = tempEnd IfNext i, jFor i = 1 To 10Print a(i);NextEnd Sub答案:=(答案1)=For i = 1 To 10=(答案2)=If a(j) > a( j + 1 ) Then=或=If a( j + 1 ) <a (j) Then=(答案3)=Next j, i第40题 (1.0分) 题号:141'-'【程序改错】'-'题目:输
42、出40以内能够被3整除的数,要求输出结果为5' 个数一行。'-Option ExplicitPrivate Sub Form_Click()ClsDim x As IntegerDim i As Integeri = 1For x = 1 To 40If (x / 3) = (x 3) Then Print x i = i + 1End If If i Mod 3 = 0 Then PrintEnd IfNext xEnd Sub答案:=(答案1)=i = 0=(答案2)=Print x;=(答案3)=if i mod 5=0 then第42题 (1.0分) 题号:117'-'【程序改错】'-'题目:下面的程序段用于实现以下功能:建立一顺序文'件,存放10名同学的学号和三门功课成绩,显示'该文件内所有记录, 并同时显示其总分和平均分'-Option ExplicitPrivate Sub Form_Click()Dim no%, c1%, c2%, c3%, i As IntegerOpen "c:2.txt" For Input As #1For i = 1 To 10 no = InputBox("请输入学号") c1 = InputBox(&
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 线下直播带货课程设计
- 研学课程设计剪纸
- 水控课程设计致谢模板
- 2024年吉林省安全员-B证考试题库附答案
- 油品储存与装卸课程设计
- 研学课程设计措施和方法
- 电池课程设计目录
- 2024江西省安全员《B证》考试题库
- 2025四川省建筑安全员《B证》考试题库
- 2025天津市安全员-C证(专职安全员)考试题库
- 齐鲁名家 谈方论药智慧树知到期末考试答案2024年
- 2024年华电甘肃大基地煤电分公司招聘笔试参考题库含答案解析
- 2022年度设备部安全生产工作计划5篇
- GB∕T 39757-2021 建筑施工机械与设备 混凝土泵和泵车安全使用规程
- 英国学派多元主义与社会连带主义论争
- 电梯公司安全生产管理制度汇编.doc
- 儿童保健档案表.doc
- 阀门检测报告
- 新产品开发流程表
- 保命未来经0001
- 北京市养老机构公建民营实施办法(20210220135609)
评论
0/150
提交评论