收藏 分享(赏)

程序改错--答案版.doc

上传人:cjc2202537 文档编号:229877 上传时间:2018-03-24 格式:DOC 页数:6 大小:107KB
下载 相关 举报
程序改错--答案版.doc_第1页
第1页 / 共6页
程序改错--答案版.doc_第2页
第2页 / 共6页
程序改错--答案版.doc_第3页
第3页 / 共6页
程序改错--答案版.doc_第4页
第4页 / 共6页
程序改错--答案版.doc_第5页
第5页 / 共6页
点击查看更多>>
资源描述

1、12592 题目:编程求一个十进制整数 n 的各位数字之和,设 n 为小于或等于 5 位的数。-Option ExplicitPrivate Sub Form_Click()Dim N As Integer, Sum As Integer, S1 As String, S2 As StringDim i As Integer, Ch As StringSum = 0N = InputBox(“输入整数 n“)S1 = Str(N)S1 = Trim(S1)For i = 1 To Len(S1)*ERROR*Ch = Mid(N, i, 1)*ERROR*Sum = Val(Ch)Next i

2、Print “该整数的各位数之和是:“; SumEnd Sub答案:Ch=Mid(S1 , i , 1)Sum = Sum + Val(Ch) 12610题目:程序功能根据输入的学习成绩,分别显示优秀(90 分以上), 良好(75 分以上),及格(60 分以上)不及格四个等级.-Option ExplicitPrivate Sub Form_Click()ClsDim i As Integeri = InputBox(“请输入学习成绩“)Select Case i*ERROR*Case 0 = Form1.Width Then3). Label1.Left = 012624.题目:程序功能:求

3、 1+2+3,直到其和超出 3000 为止,并输入结果。-Option ExplicitPrivate Sub Form_Click()ClsDim i As IntegerDim s As Singlei = 1*ERROR*s = 0Do*ERROR*i = i + 2s = s + i*ERROR*Loop s 3000Print “从 1 到:“; i; “ 的和是“; sEnd Sub答案:s = 1i = i +1Loop Until s 300012629.题目:下面的程序段用于实现以下功能:建立一顺序文件,存放 10 名同学的学号和三门功课成绩,显示该文件内所有记录, 并同时显

4、示其总分和平均分。-Option ExplicitPrivate Sub Form_Click()Dim no%, c1%, c2%, c3%, i As Integer*ERROR*Open “c:2.txt“ For Input As #1For i = 1 To 10no = InputBox(“请输入学号“)c1 = InputBox(“请输入数学成绩“)c2 = InputBox(“请输入语文成绩“)c3 = InputBox(“请输入外语“)Write #1, no, c1, c2, c2Next iClose #1*ERROR*Open “c:2.txt“ For Output

5、As #1For i = 1 To 10*ERROR*Print #1, no, c1, c2, c3Print no, c1, c2, c3, c1 + c2 + c3, (c1 + c2 + c3) / 3Next iClose #1End Sub答案: 1) Open “c:2.txt“ For Output As #12) Open “c:2.txt“ For Input As #13)Input #1, no, c1, c2, c312677.题目:求s=72+102+132+832 的值。-Option ExplicitPrivate Sub Form_Click()ClsDim

6、s As LongDim i As Integer*ERROR*s = 1*ERROR*For i = 7 To 832s = s + i*ERROR*loop 30Print sEnd Sub答案:s=0For i = 7 to 832 step 30Loop until 3012683.题目:产生 30 个小于 100 的成绩随机数,并统计出优、良、中等、及格、不及格数的个数,并计算出成绩属于优秀段的成绩平均分。-Option ExplicitPrivate Sub Form_Click()Dim k%, a%, bjg%, jg%, zd%, lh%, yx As IntegerDim

7、pjf As IntegerRandomizepjf = 0For k = 1 To 30*ERROR*a = Int(Rnd()Select Case aCase 0 To 59bjg = bjg + 1 不及格Case 60 To 69jg = jg + 1 及格Case 70 To 79zd = zd + 1 中等Case 80 To 89lh = lh + 1 良好Case 90 To 100yx = yx + 1 优秀*ERROR*pjf = pjf + 1End SelectNext k*ERROR*If yx 0 Then pjf = pjf / 30Debug.Print “不

8、及格“ + Str$(bjg) + “人,及格“ + Str$(jg) + “人,中等“ + Str$(zd) + “人“;Debug.Print “良好“ + Str$(lh) + “优秀“ + Str$(yx) + “人“Debug.Print “优秀分数段成绩平均分“ “9*9 table“Print: PrintPrint “ * “;For i = 1 To 9*ERROR*Print Tab(i * 6); iNext iPrintFor j = 1 To 9Print j; “ “;*ERROR*For k = 1 To 9*ERROR*Print Tab(j * 6); j *

9、 k; “ “;Next kPrintNext jEnd Sub答案:Print Tab(i* 6) ; i ; For k =1 To j Print Tab(k*6) ; j * k ; “ “ ; 12701.题目:用辗转相除法求两个整数的最大公约数。-Option ExplicitFunction gcd(ByVal m As Integer, ByVal n As Integer) As IntegerDim r As Integerr = m Mod nDo While r 0*ERROR*n = mn = rr = m Mod nLoop*ERROR*gcd = rEnd Fun

10、ctionPrivate Sub Form_Click()Dim a As Integer, b As Integer, c As Integera = InputBox(“输入一个整数“)b = InputBox(“输入一个整数 “)a = Val(a)b = Val(b)*ERROR*Call gcd(a, b)Print a, b, cEnd Sub答案:m = n gcd = n c= gcd(a,b)12710.题目:输出 40 以内能够被 3 整除的数,要求输出结果为 5 个数一行。-Option ExplicitPrivate Sub Form_Click()ClsDim x A

11、s IntegerDim i As Integer*ERROR*i = 1For x = 1 To 40If (x / 3) = (x 3) Then*ERROR*Print xi = i + 1End IfIf i Mod 5 = 0 ThenPrintEnd If*ERROR*step iEnd Sub答案:i = 0Print Tab( i Mod 5 ) * 8 ) ; x ;Next x12720.题目:请根据下列描述编写购物优惠程序。某商场为了 加速促成商品流通,采用购物打折的优惠办法,每 位顾客一次购物(1)在 100 元以上者,按九五折优惠; (2)在 200 元以上者,按九折

12、优惠;(3)300 元以上 者,按八折优惠;(4)500 元以上者按七折优惠。-Option ExplicitPrivate Sub Command1_Click()Dim x As Single, y As Singlex = Val(Text1.Text)If x 0 And x = 10 Then*ERROR*For k = x To 10*ERROR*a(k) = a(k -1)Next kPrint “删除后的数组:“For i = 1 To 9Print a(i);Next iElsePrint “删除位置错误“*ERROR*EndEnd Sub答案: For k = x to 9

13、 a(k) = a(k+1) End if 1、题目:下面程序的作用是产生100以内的全部素数,并按每行5个数据输出。Private Function prime(ByVal n As Integer)Dim i As Integerprime = 1If n = 1 Then prime = 0*ERROR*For i = 2 To n - 1If n Mod i = 0 Then prime = 0Next iEnd FunctionPrivate Sub Form_Click()Dim i As Integer, k As Integerk = 0For i = 1 To 100If prime(i) = 1 Then*ERROR*Print Tab(k Mod 5) * 8); i;k = k + 1*ERROR*If k Mod 5 = 0 Then Print ;End IfNext iEnd Sub

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 教育学

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报