金陵科技学院2012年vb期末考试题目(3).doc

上传人:xins****2008 文档编号:108417983 上传时间:2019-10-23 格式:DOC 页数:7 大小:161.50KB
返回 下载 相关 举报
金陵科技学院2012年vb期末考试题目(3).doc_第1页
第1页 / 共7页
金陵科技学院2012年vb期末考试题目(3).doc_第2页
第2页 / 共7页
金陵科技学院2012年vb期末考试题目(3).doc_第3页
第3页 / 共7页
金陵科技学院2012年vb期末考试题目(3).doc_第4页
第4页 / 共7页
金陵科技学院2012年vb期末考试题目(3).doc_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《金陵科技学院2012年vb期末考试题目(3).doc》由会员分享,可在线阅读,更多相关《金陵科技学院2012年vb期末考试题目(3).doc(7页珍藏版)》请在金锄头文库上搜索。

1、金陵科技学院2012-2013年第一学期Visual Basic期末考试范围(题目及答案) M12机械设计制造及其自动化(专转本)丁世斌 整理于2012/12/27四程序改错。【改错题1】下列程序的功能是找出100-999之间所有素数,请修改程序。Private Sub Command1_Click() Dim i As Integer, k As IntegerFor i = 100 To 999 For k = 2 To i If i Mod k = 0 Then Exit For End If Next i If k i Then Print i End IfNext k End Sub

2、正确答案。Private Sub Command1_Click()Dim i As Integer, k As IntegerFor i = 100 To 999For k = 2 To sqr(i)If i Mod k = 0 ThenExit ForEnd IfNext kIf k sqr(i) ThenPrint iEnd IfNext iEnd Sub【改错题2】本程序的功能是:查找800-1200范围内的所有具有两个相同数字的素数。例如811、877等都是符合要求的数据。程序界面如下图所示:图1-51 具有两个相同数字的素数Option Explicit Private Sub Co

3、mmand1_Click() Dim i As Integer For i = 800 To 1200 If validate(i) And prime(i) Then List1.AddItem i End If Next i End Sub Private Function validate(n As Integer) As Boolean Dim num() As Integer, k As Integer Dim i As Integer, j As Integer Do k = k + 1 ReDim num(k) num(k) = n Mod 10 n = n 10 Loop Un

4、til n = 0 k = 0 For i = 1 To UBound(num) - 1 For j = i + 1 To UBound(num) If num(i) = num(j) Then k = k + 1 Next j Next If k = 1 Then validate = True End Function Private Function prime(n As Integer) As Boolean Dim i As Integer For i = 2 To Sqr(n) If n Mod i = 0 Then Exit For Next i prime = True End

5、 Function正确答案:Option Explicit Private Sub Command1_Click() Dim i As Integer For i = 800 To 1200 If validate(i) And prime(i) Then List1.AddItem i End If Next i End Sub Private Function validate(ByVal n As Integer) As Boolean Dim num() As Integer, k As Integer Dim i As Integer, j As Integer Do k = k +

6、 1 ReDim Preserve num(k) num(k) = n Mod 10 n = n 10 Loop Until n & hw & &o List1.AddItem st End If Next iEnd SubPrivate Sub hw8(n As Integer, hw As String, f As Boolean) Dim k As Integer, st() As String * 1, i As Integer hw = Do k = k + 1 ReDim Preserve st(k) st(k) = n Mod 8 hw = st(k) & hw n = n 8

7、Loop Until n 0 For i = 1 To UBound(st) / 2 If st(i) st(UBound(st) - i + 1) Then Exit For Next i f = TrueEnd Sub正确答案:Option ExplicitPrivate Sub Command1_Click() Dim i As Integer, hw As String, fg As Boolean Dim st As String For i = 80 To 150 fg = False Call hw8(i, hw, fg) If fg Then st = CStr(i) & =

8、& hw & &o List1.AddItem st End If Next iEnd SubPrivate Sub hw8(byval n As Integer, hw As String, f As Boolean) Dim k As Integer, st() As String * 1, i As Integer hw = Do k = k + 1 ReDim Preserve st(k) st(k) = n Mod 8 hw = st(k) & hw n = n 8 Loop Until n = 0 For i = 1 To UBound(st) / 2 If st(i) st(UB

9、ound(st) - i + 1) Then Exit sub Next i f = TrueEnd Sub【改错题4】本程序功能是查找给定范围内满足以下条件的整数数对。条件1是每个整数的各位数字各不相同,且不得为数字0,条件2是第二个数等于第一个数的两倍。例如123和246就是符合条件的数对。程序界面如下图所示:图1-53 查找数对Option ExplicitPrivate Sub Command1_Click() Dim i As Integer Dim n As Integer For i = 123 To 5678 n = i * 2 If fun(i) And fun(n) The

10、n List1.AddItem ( & i & , & n & ) End If Next iEnd SubPrivate Function fun(n As Integer) As Boolean Dim a() As Integer, i As Integer, j As Integer Do i = i + 1 ReDim Preserve a(i) a(i) = n Mod 10 If a(i) = 0 Then Exit Function n = n 10 Loop Until n 0 For i = 1 To UBound(a) - 1 For j = i + 1 To UBound(a) If a(i) = a(j) Then Exit For Next j

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 教学课件 > 高中课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号