已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1级数数列求和 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim m, i, n As Integer Dim s, j As Double n = InputBox(请输入n的值 & n) i = 0 m = 1 s = 2 For i = 1 To n i = i + 1 m = m + i j = 1 + 1 / i s = s + j NextMsgBox(Str(s) End SubEnd Class2求回文数Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i, ww, qw, sw, gw, k As Integer Dim str1 As String str1 = For i = 10000 To 50000 ww = i / 10000 qw = (i Mod 10000) / 1000 sw = (i Mod 100) / 10 gw = i Mod 10 If ww = gw And qw = sw Then k = k + 1 If k Mod 5 = 0 Then str1 = str1 + Str(i) + vbCrLf Else : str1 = str1 + Str(i) End If End If Next MsgBox(Str(k) + vbCrLf + str1) End SubEnd Class3求素数 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i, j, k, s As Integer Dim str1 As String str1 = For i = 3 To 100 For j = 2 To i - 1 If i Mod j = 0 Then Exit For End If Next j If j = i Then k = k + 1 If k Mod 5 = 0 Then str1 = str1 + Str(i) + vbCrLf Else : str1 = str1 + Str(i) End If End If Next MsgBox(str1) End SubEnd Class求完全数Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i, j, k, s As Integer Dim str1 As String str1 = For i = 2 To 10000 s = 0 For j = 1 To i / 2 If i Mod j = 0 Then s = s + j End If Next If i = s Then k = k + 1 If i Mod 5 = 0 Then str1 = str1 + Str(i) + vbCrLf Else : str1 = str1 + Str(i) End If End If Next MsgBox(k= + k.ToString() + vbCrLf + str1) End SubEnd Class矩阵最大元素查找 Dim a(,), n, m, i, j As Integer Dim max, row, col As Integer Dim str1 As String n = Val(InputBox(请输入矩阵行数n=) m = Val(InputBox(请输入矩阵列数m=) ReDim a(n - 1, m - 1) For i = 0 To n - 1 For j = 0 To j - 1 a(i, j) = Val(InputBox(请输入 & i & 行 & j & 列元素的值) str1 = str1 + Str(a(i, j) + Space(4) Next j str1 = str1 + Chr(10) + Chr(13) Next i max = a(0, 0) For i = 0 To n - 1 For j = 0 To m - 1 If a(i, j) max Then max = a(i, j) row = i col = j End If Next j Next i TextBox1.Text = str1 TextBox2.Text = max TextBox3.Text = row TextBox4.Text = col2、习题7-7 矩阵转置Dim a(,), b(,), n, m, i, j As Integer Dim str1, str2 As String n = Val(InputBox(请输入矩阵行数n=) m = Val(InputBox(请输入矩阵列数m=) ReDim a(n - 1, m - 1) ReDim b(m - 1, n - 1) For i = 0 To n - 1 For j = 0 To m - 1 a(i, j) = Val(InputBox(请输入 & i & 行 & j & 列元素的值) str1 = str1 + Str(a(i, j) + Space(4) Next j str1 = str1 + Chr(13) + Chr(10) Next i For i = 0 To m - 1 For j = 0 To n - 1 b(i, j) = a(j, i) str2 = str2 + Str(b(i, j) + Space(4) Next j str2 = str2 + Chr(13) + Chr(10) Next i TextBox1.Text = str1 TextBox2.Text = str23、习题7-8 矩阵输入/输出,行/列求和,元素对换 Dim a(3, 3), i, j As Integer Dim str1, str2 As String For i = 0 To 3 For j = 0 To 3 a(i, j) = Val(InputBox(请输入 & i & 行 & j & 列元素的值) If i = j And i + j = 3 Then str1 = str1 + Str(a(i, j) End If Next Next MsgBox(str1) Dim s1, s2 As Integer Dim a(3, 3), i, j As Integer s1 = s2 = 0 For i = 0 To 3 For j = 0 To 3 a(i, j) = Val(InputBox(请输入 & i & 行 & j & 列元素的值) s1 = a(0, j) + s1 s2 = s2 + a(i, 0) Next Next MsgBox(s1) TextBox1.Text = s2 Dim t As Integer Dim a(3, 3), i, j As Integer Dim str1 As String For i = 0 To 3 For j = 0 To 3 a(i, j) = Val(InputBox(请输入 & i & 行 & j & 列元素的值) t = a(0, j) a(2, j) = t str1 = str1 + Str(a(i, j) Next Next4、习题7-12 输出“杨辉三角形” Dim a(,), n, m, i, j As Integer Dim str1 As String ReDim a(11, 11) For i = 1 To 11 For j = 1 To i If i = j Then a(i, j) = 1 Else a(i, j) = a(i - 1, j - 1) + a(i - 1, j) End If str1 = str1 + Str(a(i, j) + Space(4) Next str1 = str1 + Chr(13) + Chr(10) Next TextBox1.Text = str1 Dim a(3, 3), i, j As Integer Dim str1, str2 As String For i = 0 To 3 For j = 0 To 3 a(i, j) = Val(InputBox(请输入 & i & 行 & j & 列元素的值) If i = j And i + j = 3 Then str1 = str1 + Str(a(i, j) End If Next Next MsgBox(str1) Dim s1, s2 As Integer 编写程序,建立并输出一个10*10的矩阵, 该矩阵主对角线和副对角线为1,其余元素为0, 结果显示在textbox1文本框中。 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim a(9, 9), i, j, n As Integer Dim str
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2021贵州公务员行测真题及答案解析
- 2024年9月昭通市直机关遴选公务员面试真题附解析
- 信息技术上机试卷(二)
- 二级建造师继续教育考试复习题库及答案指导
- 双重预防体系题库大全含答案王牌题库
- cpa审计考试题型
- 党的知识竞赛题库(含答案)-200单选-报
- 2025年麻醉科主治医师考试真题练习卷
- 对当前金融监管的几点看法
- 2025江西省考面试6月22日面试真题解析
- 集成电路芯片设计企业组织架构详解
- 2025广东深圳市罗山科技园开发运营服务有限公司第二批招聘4人笔试考试参考试题及答案解析
- 学堂在线 人工智能 章节测试答案
- 2025全国硕士研究生政治考试完整真题及答案
- 彼得·蒂尔:硅谷教父的叛逆人生
- 配送员食品安全培训课件
- 高危药品外渗预防及处理
- bz-门式轻钢结构厂房施工组织设计投标方案230
- 2025年违规吃喝谈心谈话记录
- 钢结构焊接工艺评定
- 校园安全教育安排表
评论
0/150
提交评论