版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、程序填空】1. 功能:以下程序段用于实现矩阵转置,即将一个nm 的矩阵的行和列互换Private Sub Form_Click()Const n = 3Const m = 4Dim a(n, m), b(m, m) As IntegerFor I = 1 To nFor j = 1 To ma(I, j) = Int(Rnd * 90) + 10Next jNext iFor I = 1 To nFor j = 1 To mB(I,j)=a(I,j)Next jNext IPrint 矩阵转置前 For I = 1 To nFor j = 1 To mPrint a(I, j);Next jp
2、rintNext IPrint 矩阵转置后 For I = 1 To mFor j = 1 To nPrint b(I, j);Next jPrintNext IEnd Sub1. 功能:输入数字 1-7,显示其对应是星期几 (例:输入 1,显示星期日 ,如果输入其它内容, 一律显示 输入错误 )Private Sub Command1_Click()dim x as integerdim y as stringx=val(text1.text)Select case xcase 1 y= 今天是星期日 case 2 y= 星期一 case 3 y= 星期二 case 4 y= 星期三 cas
3、e 5 y= 星期四 case 6 y= 星期五 case 7 y= 星期六 Case elsey = 输入错误 end selectText2.Text = yEnd Sub1. 功能:求 1!+2!+ +10!的值。Private Sub Form_Click()T=1s = 1For I = 2 To 10 t = t * I S=s+tNext iPrint sEnd Sub1. 功能:以下程序段用于计算 n 的阶乘: n!。( 1! =1) Public Function fac(n As Integer) As IntegerIf n = 1 Thenfac = 1Elsefac
4、= n * fac(n-1)End IfEnd FunctionPrivate Sub Command1_Click()Print fac(4)=; fac(4)End Sub1. 功能: 以下程序的功能是: 生成 20 个 200 到 300 之间的随机整数, 输出其中能被 5 整除的数并求出它们的和Private Sub Command1_Click()Dim s As IntegerDim x As Integer, i As Integers = 0For i = 1 To 20RandomizeX = Int(rnd * 100 + 200)If X mod 5 = 0 ThenPr
5、int Xs = s + XEnd IfNext iPrint Sum ; sEnd Sub1. 功能:在窗体上画一个标签(名称为Label1 )和一个计时器(名称为 Timer1 ),然后编写如下几个事件过程:要求:每一秒钟 Label1 更新显示一次系统时间Private Sub Form_Load()Timer1.Enabled = FalseTimer1.Interval = 1000End SubPrivate Sub Form_Click()Timer1.Enabled = TrueEnd SubPrivate Sub Timer1_Timer()Label1.Caption =
6、NowEnd Sub1. 功能:窗体上建立了两个文本框 Text1(输入字符串 )及 Text2( 转换结果 ),一个命令按钮 Command1( 清除 ) 。录入 Text1 内容时,将录入内容大写字母转为小写,小写转为大 写。Private Sub Command1_Click()Text1.Text = Text2.Text = Text1.SetFocusEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)Dim s As String * 1s = chr(KeyAscii)Select Case sCase A to Z s
7、= LCase(s)Case a To zs = Ucase(s)Case Elses = *End SelectText2.Text = Text2.Text + sEnd Sub1. 功能:窗体上建立了一个文本框 Text1( 输入口令 ) 和一个命令按钮 Command1( 检查 ) 。判断密码是否正确,并显示相应提示在加载窗体时设置密码框最大长度为8,密码显示字符为“ * ”dim x as stringPrivate Sub Command1_Click()x = Text1.TextIf x = 12345678 ThenMsgBox ( 欢迎你用机 !)ElseMsgBox (
8、对不起,口令错 )End IfText1.Text = Text1.SetFocusEnd SubPrivate Sub Form_Load()Text1.Text = Text1.maxlength = 8Text1.Psswordchar = *End Sub1. 功能:下面的程序段用于打印出以下图形Private Sub Form_Click() Dim i%, j%, k%For i = 0 To 3For j = 0 To 2 - i Print ;Next jFor k = 1 To 2*i+1Print *;Next kPrintNext iFor i = 0 To 2For j
9、 = 0 To iPrint “”;Next jFor k = 0 To 4 - 2 * iPrint *;Next kprintNext iEnd Sub1. 功能:下面的程序段用于求矩阵相乘C=A B,设 A 、B、C 分别为 mp、pn、m n 的矩阵。Private Sub Form_Click()Const m = 4, p = 3, n = 2Dim a(1 To m, 1 To p) As IntegerDim b(1 To p, 1 To n) As IntegerDim c(1 To m, 1 To n) As IntegerDim i As Integer, j As In
10、teger, k As Integer, sum As IntegerFor i = 1 To mFor k = 1 To pa(i, k) = iNext kNext iFor i = 1 To pFor k = 1 To nb(i, k) = iNext kNext iFor i = 1 To mFor j = 1 To nSum=0For k = 1 To psum = sum +a(I,k)*b(k,j)Next k c(i, j) =sumNext j, iPrint 输出矩阵 For i = 1 To mFor k = 1 To nPrint c(i, k),Next kPrint
11、Next iEnd Sub1. 功能:利用下面的过程求 m! 和 m*nPrivate Sub Form_Click()Dim m As Integer, n As Integerm = 2 n = 3 Find m,nEnd SubPrivate Sub find(x As Integer, y As Integer)Dim s, i As IntegerS=1For i = 1 To x s = s * i p=x*yNext iPrint s, pEnd Subx 大于 y 。1. 题目:已知用 inputbox 函数输入两个数 x 和 y,比较它们的大小,使得 Private Sub
12、Form_Click()Dim x As Single, y As Singlex = InputBox( 输入数据 1: )y = InputBox( 输入数据 2: )Print x 值, y 值Print x, yIf x y ThenT=xX=yY=tEnd IfPrint x, yEnd Sub程序改错】1. 题目:以下程序段用于打印如图 1 所示的九九乘法表:Option ExplicitPrivate Sub Form_Click()Dim i As Integer, j As Integer, k As IntegerPrint Tab(30); 9*9 tablePrint:
13、 PrintPrint * ;For i = 1 To 9Print Tab(i * 6); I;Next iPrintFor j = 1 To 9Print j; ;For k = 1 To jPrint Tab(k * 6); j * k; ;Next kPrintNext jEnd Sub1. 题目:求 s=1!+3!+5!+7! ,阶乘的计算用 Function 过程 fact 实现 . Option ExplicitPrivate Sub Form_Click()Dim i As Integer, s As IntegerFor i = 1 To 7 step 2s = s + fa
14、ct(i)Next iPrint sEnd SubPublic Function fact(ByV al n As Integer)Dim t As Integer, i As Integert = 1For i = 1 To nt = t * iNext ifact =tEnd Function1. 题目 :请根据下列描述编写购物优惠程序。某商场为了加速促成商品流通,采用购物打 折的优惠办法,每位顾客一次购物(1)在 100 元以上者,按九五折优惠; ( 2)在 200元以上者,按九折优惠; (3)300 元以上者,按八折优惠; ( 4)500元以上者按七折优 惠。Option Explic
15、itPrivate Sub Command1_Click()Dim x As Single, y As Singlex = Val(Text1.Text)If x 100 ThenY=xElseIf x 200 Then y = 0.95 * xElseIf x 300 Theny = 0.9 * xElseIf x a(n) Then t=nNext nIf t m Then w = a(m) a(m) = a(t) a(t) = wEnd IfNext mFor m = 1 To 7Print a(m)Next m End Sub5 个数一行。1. 题目:输出 40以内能够被 3 整除的数
16、,要求输出结果为 Option ExplicitPrivate Sub Form_Click()ClsDim x As IntegerDim i As Integeri = 0For x = 1 To 40If (x / 3) = (x 3) ThenPrint x;i = i + 1End IfIf i Mod 5 = 0 ThenPrintEnd Ifnext iEnd Sub1. 题目 :编程求一个 m*n 矩阵中最大元素及其所在的行列号。Option ExplicitPrivate Sub Form_Click()Dim A() As Integer, max As IntegerDi
17、m M As Integer, N As IntegerDim i As Integer, j As IntegerDim col As Integer, row As IntegerM = InputBox( 输入矩阵的行数: )N = InputBox( 输入矩阵的列数: ) ReDim A(1 To M, 1 To N) As IntegerFor i = 1 To MFor j = 1 To NA(M, N) = InputBox( 输入数组元素 :) Next jNext i max = A(1,1)For i = 1 To MFor j = 1 To NIf max 3000Pri
18、nt 从 1 到:; i; 的和是; s End Sub1. 题目:用辗转相除法求两个整数的最大公约数。Option ExplicitFunction gcd(ByV al m As Integer, ByV al n As Integer) As IntegerDim r As Integer r = m Mod nDo While r 0M=n n = r r = m Mod nLoopgcd = nEnd FunctionPrivate Sub Form_Click()Dim a As Integer, b As Integer, c As Integera = InputBox( 输入
19、一个整数 )b = InputBox( 输入一个整数 )a = Val(a)b = Val(b)c=gcd(a, b)Print a, b, cEnd Sub1. 题目 :密码判断程序, 如果密码为 12345 则显示 “恭喜, 密码正确”,否则显示 “很遗憾, 密码错误”,要求文本框中只允许输入数字。Option ExplicitPrivate Sub Command1_Click()Dim strPws As String strPws = Trim(Text1.Text)If Len(strPws) = 0 Then Exit SubIf strPws = 12345 ThenMsgBo
20、x 恭喜,密码正确 , , 验证ElseMsgBox 很遗憾,密码错误 , , 验证 End IfEnd SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)If Not (KeyAscii = 48 And KeyAscii = 57) Then KeyAscii = 0End IfEnd Sub832 的值。1. 题目:求 s=72+102+132+ Option ExplicitPrivate Sub Form_Click()ClsDim s As LongDim i As Integers = 0For i = 7 To 832 step
21、 30s = s + inext iPrint s End Sub1. 题目:下边是一个小动画程序,在窗体上放一个标签 Label1 ,每过 1 秒钟标签 Label1 的背景颜色由红到蓝, 由蓝到绿,再由绿到红循环变化, 并自动修改标签 Label1 的 Left , Top 值使其从左上角沿窗体的对角线移动到窗体的右下角,如此往复从而实现动画。Option ExplicitPrivate flag As IntegerPrivate Sub Form_click()Timer1.Enabled = TrueEnd SubPrivate Sub Form_Load()Timer1.Inter
22、val = 1000Label1.Left = 0Label1.Top = 0Label1.BackColor = vbBlack Timer1.Enabled = FalseEnd SubPrivate Sub Timer1_Timer()If Label1.Left Left + Width And Label1.Top = Top + Height ThenLabel1.Left = Label1.Left + 100 * Width / HeightLabel1.Top = Label1.Top + 100ElseLabel1.Left = LeftLabel1.Top = TopEn
23、d IfIf flag = 0 ThenLabel1.BackColor = vbBlueflag = 1ElseIf flag = 1 ThenLabel1.BackColor = vbGreenflag = 2ElseLabel1.BackColor = vbRedflag = 0End IfEnd Sub程序设计】1. 题目: (事件 )单击窗体。 (响应 )求 200300 之间既能被 3 整除又能被 7 整除的数。并求 出所有数之和存入变量 SUM 中Private Sub Form_Click()Dim sum As Integersum = 0Dim i As IntegerFor i = 201 To 300If (i Mod 3) = 0) And (i Mod 7) = 0) ThenPrint (CStr(i)sum = sum + iEnd IfNextPrint sumYZJ (sum)End SubPrivate Sub YZJ(i As Integ
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 冰场装修施工合同模板
- 商业空间装修项目管理合同
- 家政临时绿化居间协议
- 家具快递安装配送合同样本
- 保健食品佣金居间合同模板
- 仓储租赁佣金居间合同样本
- 互联网教育借款居间服务
- 上海市数码广场装修协议
- 冷链冰淇淋运输协议
- 保安服务居间合同格式
- 统编人教部编版语文一年级上册第四单元编写意图解读及使用建议教材解读分析及教学建议教研集体备课校本培训课件
- 黑色渐变文明交通安全出行中学生交通安全教育课PPT模板
- 热导率的测量课件
- 山东省烟台市2022~2023学年八年级上学期期中阶段性测试数学【含答案】
- 悬臂浇筑连续梁施工作业指导书
- Unit 3 Just a brother 阅读理解课件-高中英语外研版必修第一册
- 酸奶的制作课件1
- 建筑材料进场验收制度页
- 班主任经验交流-课件(共18张)
- 7的乘法口诀(省一等奖)课件
- 谢公与人围棋文言文阅读答案
评论
0/150
提交评论