ImageVerifierCode 换一换
格式:DOCX , 页数:26 ,大小:196.18KB ,
资源ID:9822491      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/9822491.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(第七章答案.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

第七章答案.docx

1、第七章答案第七章 习题答案1在过程中声明的局部变量其生命期只到本次过程执行结束就终止了,但是在过程中声明的静态变量其生命期是只有当包含此过程的窗体被终止的时候才终止。2有三种形式,传值、传址和利用全局变量向过程传递数据。 传值:给过程传递的是变量的值,不会有副作用。 传址:给过程传递的是变量的地址,有副作用 利用全局变量:有副作用,3Private Sub C1_Click() Dim i As Integer, j As Integer i = 8: j = 8 Call aa(i, j) Print i Print jEnd SubPrivate Sub aa(ByVal m As Int

2、eger, ByRef n As Integer) m = m + 1 n = n + 1End Sub 4(1) BASIC (2) 第一行: 6 26;第二行: 2 62;第三行: -2 98 (3) 第一行: 23 ; 第二行: 47 (4) 第一行: 10 8; 第二行:12 -10;第三行:5 2;第四行:12 -105Private Sub Command1_Click() Dim ss As Single, hs As Single ss = Text1 Text2 = tra(ss)End SubPrivate Sub Command2_Click() Text1.Text =

3、 Text2 = End SubPrivate Sub Command3_Click() EndEnd SubPublic Function tra(ByVal C As Single) As Single Dim F As Single F = (C * 9) / 5 + 32 tra = FEnd Function6. Private Sub Command1_Click() Dim data_one As Integer data_one = InputBox(请输入要判断的数:, 素数判断) If Prime(data_one) Then sushu = Str(data_one) +

4、 是素数 else sushu = Str(data_one) + 不是素数 End IfEnd SubPrivate Sub Command2_Click() Text1 = End SubPrivate Sub Command3_Click() EndEnd SubPublic Function Prime(ByVal N As Integer) As Boolean Dim k As Integer For k = 2 To Sqr(N) If N Mod k = 0 Then Exit Function Next k Prime = TrueEnd Function7.Private

5、Sub Command1_Click() Dim ss As String Dim i As Integer For i = 1 To 100 If Prime(i) And Prime(i + 2) Then ss = ss & Chr(13) & Chr(10) & i & Str(i + 2) End If Next i Text1 = ssEnd SubPublic Function Prime(ByVal N As Integer) As Boolean Dim k As Integer For k = 2 To Sqr(N) If N Mod k = 0 Then Exit Fun

6、ction Next k Prime = TrueEnd Function8. Option ExplicitOption Base 1Private Sub Form_Click() Dim a As Integer, n As Integer Dim i As Integer Randomize Dim aa(20) As Integer a = Int(100 * Rnd() * 1) n = 1 Do For i = 1 To n - 1 If a = aa(i) Then Exit For End If Next i If i = n Then aa(n) = a n = n + 1

7、 End If a = Int(100 * Rnd() * 1) Loop While n Max Then Max = s maxi = i End If Next i Print Str(a(maxi) & + & Str(a(maxi + 1) & + & Str(a(maxi + 2) & + & Str(a(maxi + 3) & = & Str(Max)End Sub10. Private Sub Command1_Click() Dim a(5, 5) As Integer Randomize For i = 1 To 5 For j = 1 To 5 a(i, j) = Int

8、(100 * Rnd) + 1 Print a(i, j); Next j Print Next i Call fmax(a)End SubPrivate Sub fmax(a() As Integer) Max = a(1, 1) maxi = 1 maxj = 1 For i = 1 To 5 For j = 1 To 5 If a(i, j) Max Then Max = a(i, j) maxi = i maxj = j End If Next j Next i Print 最大元素为:a( + Str(maxi) + , + Str(maxj) + )= + CStr(Max)End

9、 Sub11 . Private Sub Command1_Click() Dim i As Integer For i = 1 To 6 Text1 = Text1 & Str(fab(i) Next iEnd SubPrivate Function fab(n As Integer) As Long If n = 1 Or n = 2 Then fab = 1 Else fab = fab(n - 1) + fab(n - 2) End IfEnd Function12 .Private Sub Command1_Click() Dim i As Integer a = InputBox(

10、请输入一个大于2的偶数:) n = Val(a) If n = 4 Then Print 4 = 2 + 2 Exit Sub End If For i = 3 To n - 1 Step 2 If prime(i) And prime(n - i) Then Print Str(n) + = + Str(i) + + + Str(n - i) Exit Sub End If Next i Print 歌德巴赫猜想不对!End SubPrivate Function prime(ByVal n As Integer) As Boolean For i = 2 To n - 1 If n Mod

11、 i = 0 Then prime = False Exit Function End If Next i prime = TrueEnd Function13.Private Sub Command1_Click() Dim i As Integer For i = 10 To 9999 Call arm(i) Next iEnd SubPrivate Sub arm(j As Integer) a = CStr(j) n = Len(a) For k = 1 To n b = Mid(a, k, 1) s = s + Val(b) n Next k If s = j Then Print

12、j End IfEnd Sub14.Private Sub Command1_Click() Dim n As Integer, m As String, b As Integer n = InputBox(请输入原始数的进制(2-16):) m = InputBox(请输入原始数:) Label1.Caption = Str(n) + 进制数 Text1 = m b = trans(m, n) Text2 = Str(b)End SubPrivate Function trans(m As String, n As Integer) As Integer Dim k As Integer,

13、t As String, r As Integer, s As Integer k = Len(m) For i = 1 To k t = UCase(Mid(m, i, 1) If t = A And t Max Then Max = b(i) If b(i) Max Then Max = b(i) If b(i) Min Then Min = b(i) Sum = Sum + b(i) Next i Sum = Sum - Max - Min Text1 = Str(Sum / 4)End Sub16.Private Sub Command1_Click() Dim i As Intege

14、r, k As Integer, m As Integer Dim s As Single, t As Single i = 1 Do t = 1 For k = 1 To i m = 2 * k t = t * m Next k s = s + 1 / t If 1 / t 0.00001 Then Exit Do i = i + 1 Loop Print sEnd Sub17.Private Sub Command1_Click() Dim n As Integer, t As Single, s As Single, x As Single n = 2: s = 0 x = InputB

15、ox(input x:) Do t = (x f(n) / (f(n - 1) * f(n) s = s + t If t sort(2) Then temp = sort(1) sort(1) = sort(2) sort(2) = temp End If For i = 3 To ub flg = False flg1 = False temp = sort(i) If temp sort(1) Then flg = True mid = 0 End If left = 1 right = i - 1 Do While left = right And Not flg mid = Int(

16、left + right) / 2) If sort(mid) = temp Then flg1 = False Exit Do ElseIf sort(mid) 25 Then Exit Do aa(2, num) = 0 cnt = 0 End If ct = ct + 1 Do While ct cnt num = num + 1 If num 25 Then num = num Mod 25 cnt = aa(2, num) + cnt Loop Loop XXX = bb(25)End Function20.Option ExplicitDim ss As StringPrivate

17、 Sub C1_Click() Call great_zs T1 = ssEnd Sub产生6个不同的数Public Sub great_zs() Dim shu_1 As Integer, shu_2 As Integer, shu_3 As Integer, shu_4 As Integer, shu_5 As Integer, shu_6 As Integer Dim shu As Single For shu_1 = 1 To 9 For shu_2 = 1 To 9 For shu_3 = 1 To 9 For shu_4 = 1 To 9 For shu_5 = 1 To 9 Fo

18、r shu_6 = 1 To 9 shu = Val(CStr(shu_1) & CStr(shu_2) & CStr(shu_3) & CStr(shu_4) & CStr(shu_5) & CStr(shu_6) If lala(shu) And zhishu(shu) Then ss = ss + Str(shu) 把满足要求的数记录到变量 ss 中 Next shu_6 Next shu_5 Next shu_4 Next shu_3 Next shu_2 Next shu_1End Sub判断相邻的两个数是否为素数Public Function zhishu(ByVal zss As

19、 Single) As Boolean Dim i As Integer, jud As Integer For i = 1 To 5 jud = Val(Mid(CStr(zss), i, 1) + Val(Mid(CStr(zss), i + 1, 1) If Not Prime(jud) Then Exit Function Next i If Not Prime(Val(Mid(CStr(zss), 6, 1) + Val(Mid(CStr(zss), 1, 1) Then Exit Function zhishu = TrueEnd Function判断素数Public Functi

20、on Prime(ByVal N As Integer) As Boolean Dim k As Integer For k = 2 To Sqr(N) If N Mod k = 0 Then Exit Function Next k Prime = TrueEnd Function判断数列中的数是否各不相同Public Function lala(ByVal la As Single) As Boolean Dim i As Integer, j As Integer For i = 1 To 6 For j = 1 To 6 If Mid(CStr(la), i, 1) = Mid(CStr(la), j, 1) And i j Then Exit Function Next j Next i lala = TrueEnd Function21.Private Sub Command1_Click() Dim i As Intege

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1