付费下载
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1、生成随机数Private Sub Comma nd1_Click()Dim m As In teger, n As In tegerm = Int(Rnd * 900+ 100)n = In t(R nd * 900 + 100)Textl.Text = mText2.Text = nEnd Sub2、生成30个数组3、Dim a(30) As In tegerPrivate Sub Comma nd1_Click()randomizeFor i = 1 To 30a(i) = In t(R nd * 101 + 100)Textl.Text = Textl.Text & Str(a(i)
2、 Next I End Sub如果在text生成多行数组需要将text的multiline属性改为true3、在picture里生成数组For i=1 to 5 for j =1 to 4A(i,j)=i nt(rnd*90)+10Picture1.print a(i,j);寺别注意英文分号Next j picture1.print n ext i4、生成无重复的两位随机数Option Explicit 强制变量说明Optio n Base 1 数组下限从1开始Private Sub Comma nd1_Click()Dim a(10) As Integer, n As Integer, i
3、AsIn teger, k As In tegerRandomizea(1) = In t(90 * Rnd + 10)k = 1Don =In t(90 * Rnd + 10)For i =:1 To k fa(i)=n The n Exit ForNext IIf i k The nk = k + 1a(k)=n End IfLoop Until k = 10For i =:1 To 10Text1 = Text1 & Str(a(i)Next IEnd Sub5、产生20个2040之间的两位数,统计不同数据出现的次数 Optio n ExplicitDim A(1 To 2, 1 To
4、10) As In teger, b(20 To 40)As In teger, i%, j%, n%Private Sub Comma nd1_Click()For i = 1 To 2 For j = 1 To 10A(i, j) = In t(20 * Rnd + 20.5)Text1 = Text1 & A(i, j) Next jText1 = Text1 & vbCrLfNext I End SubPrivate Sub Comma nd2_Click() For i = 1 To 2 For j = 1 To 10 b(A(i, j) = b(A(i, j) + 1 Next j
5、 Next iFor i = 1 To 2 For j = 1 To 10Next j Next IFor n = 20 To 40If b(n) 0 Then List1.Addltem n & 出现: & b(n) & ” 次 ” Next n End Sub6、判断自首数Private Sub Comma nd1_Click() Dim x As Long x = Val(Text1.Text)If verify(x) Then 调用程序判断List1.Addltem x ElseMsgBox Str(x) &不是自守数。,vbln formati onEnd If End SubPri
6、vate Function verify(x As Long) As BooleanDim y As Long, s As In teger, z As In teger verify = Falsey = x * xs = Len( CStr(x)If x = Val(Right(CStr(y), s) Then verify = True_En d_F unction.7、最大公约数1Private Sub Comma nd2_Click()Dim m As Integer, n As Integer, s As Integer m = val(Text1.Text) n = (Text2
7、.Text) Text3.Text = lcr(m, n) End SubFunction lcr( ByVal x As Integer, ByVal y As Integer)Dim a As In tegera = x Mod yIf a = 0 The nIcr = yElse x = y y = a lcr = lcr(x, y) End IfEnd Function最大公约数2、Private Sub Form_Click()Dim m As Integer, n As Integer, r As Integer Do m = InputBox(输入一个数 m)n = InputB
8、ox(输入一个数 n)|lf m 0 And n 0 The n Exit Do Print data error! Loop Do r = m Mod n m = n n = rLoop Un til r = 0Print 最大公约数是:;mEnd Sub8、最小公倍数 Option Explicit Private Sub Comma nd1_Click()Dim m As Integer, n As Integer, rAs In tegerm = Val(Textl.Text)n = Val(Text2.Text)Do r = m Mod n If r 0 Thenm = n n =
9、r Else Exit DoEnd If LoopText3.Text = Val(Text1.Text) *Val(Text2.Text) / n End Sub9、判断素数并记录有几个素数Private Sub Comma nd3_Click()Dim m As Integer, n As Integer, i As Integer, jAs In teger, s As In tegerm = Text1.Text n = Text2.Text s = 0For i = 1 To m - 1If m Mod i = 0 Then Exit ForNext IIf m = i Thens
10、= s + 1End IfFor j = 1 To n -1 If n Mod j = 0 The nExit ForNext jIf n = j Thens = s + 1 End IfText4.Text = sEnd Sub筛选素数 For i = 1 To 30 For j = 2 To a(i)-1If a(i) Mod j = 0 Then Exit For Next j If a(i) = j Then Text4.Text = Text4.Text & Str(a(i) End If Next I End Sub 求 N 以内素数 Private Sub Form_Click(
11、)Dim n As Integer, m As Integer, k As Integer, i As Integer n = InputBox(输入一个数 n) m = 3 Do k = In t(Sqr(m)i = 2Do If m Mod i = 0 The nExit DoElse i = i + 1 End If Loop Un til i k If i = k + 1 The n Print m m = m + 1 Loop Un til m nEnd Sub求大于N的最小素数Do n = n + 1 For i = 2 To n - 1If n Mod i = 0 Then Ex
12、it For Next iIf i = n The nText2.Text = nEnd If Loop Un til Text2.Text Label2.Caption =大于& Val(Text1.Text) & 的最小素数是 End Sub10、找出100-999间的升序数(降序 数)Opti on ExplicitPrivate Sub Comma nd1_Click()Dim i As In teger, r1 As In teger,r2 As In teger, r3 As In tegerFor i = 100 To 999可以换成数组一样 r1 = i 100 r2 = (i
13、 10)Mod 10 r3 = (i Mod 100) Mod 10If r1 r2 And r2 max Thenmax = a(i, j) row = Icol = j End If Next j Next I Text1.Text = maxText2.Text = rowText3.Text = col End Subinputbox输入矩阵,求出每一行最大最小数Private Sub Comma nd1_Click()Dim a(4, 3) As Integer, i As Integer, j As In teger Dim max As In tegerFor i = 1 To
14、4For j = 1 To 3a(i, j) = InputBox(请输入矩阵的第(& i & ,& j & )元素,输入矩阵元素) Picture1.Pri nt a(i, j) Next jPicture1.Pri nt Next iFor i = 1 To 4 max = a(i, 1) For j = 2 To 3 If max rn darray(j + 1) Then t = rndarray(j + 1) : rndarray(j + 1) = rndarray(j) rndarray(j) = t End If Next j Next i | Picture1.PrintPic
15、ture1.Print 排序后:|For i = 1 To 10 Picture1.Pri nt rndarray(i);Next IPicture1.Pri ntEnd SubPrivate Sub Comma nd2_Click()Picturel.CIs Listl.Clear Textl.SetFocusEnd Sub13、产生10个2050之间的两位数,用二 分法查找数,并输出排序后的位置Optio n Base 1 Dim rndarry(10) As In teger Private Sub Comma nd1_Click(l ndexAsIn teger)Picturel.CI
16、sDim i As In teger, j As In teger, temp As In teger RandomizePicture1.Print 排序前:”For i = 1 To 10 rndarry(i) = In t(90 * Rnd + 10) Picture1.Pri nt rndarry(i);Next iFor j = 1 To 10 For i = 1 To 10 - jIf rn darry(i) rn darry(i + 1) The ntemp = rn darry(i)rn darry(i) = rn darry(i + 1)rn darry(i + 1) = t
17、emp End If Next i Next jPicture1.Pri ntPicture1.Print 排序后 For i = 1 To 10Picture1.Pri nt rndarry(i);Next iPicture1.Pri nt End SubPrivate Sub Comma nd2_Click(l ndexAsIn teger)Dim sl as In tegersl = 0 For i = 1 To 10If rndarry(i) = Val(Text1.Text) The nText2.Text =要查找的数是第” & i & ”个数 据。sl = 1 End If Ne
18、xt iIf sl = 0 Then Text2.Text =不存在! End Sub14、求和 Private Sub Command3_Click() Text3.Text = sum(a) End SubFunction sum (b() As Integer)For i = 1 To 30 sum = sum + a(i)Next I End Fu nction15、随机二维数组每一行每一列元素之和Dim a(4, 5) As In tegerPrivate Sub Comma nd1_Click()For i = 1 To 4Forj = 1 To 5a(i, j) = In t(9
19、 * Rnd) + 1Picture1.Pri nt a(i, j);Next jPicture1.Pri ntNext I End SubPrivate Sub Comma nd2_Click()For j = 1 To 5 s = 0 For i = 1 To 4s = s + a(i, j)Next I Text1 = Text1 & Str(s)Next j End SubPrivate Sub Comma nd3_Click()For i = 1 To 4 s = 0 For j = 1 To 5s = s + a(i, j) Next jText2 = Text2 & Str(s)
20、 & Chr(13) & Chr(10)Next I End Sub16、求阶乘 Private Sub Command1_Click() Dim n As Integer, s As Integer, i As Integern = lnputBox(输入一个数 n:)s = 1For i = 1 To ns = s* INext IPrint n & ”个数累乘积为:” & s| End Sub17、求勾股数 Option ExplicitPrivate Sub Comma nd1_Click()Dim a As Long, b As Long, c As Long For a = 1 T
21、o 100 For b = 1 To 100For c = 1 To 100If a * a + b * b = c * c The n List1.AddItem a & , & b & ,& cEnd If Next c Next b Next a End Sub18、判断是否为偶数(奇数)Private Sub cmdjudge_Click()Dim n As In tegern = Text1.TextIf n Mod 2 = 0 The nMsgBox n & 是偶数”ElseMsgBox n & ” 不是偶数End If End Sub19、生成10个1099之间的整数,并分别 求
22、出其中偶数与奇数的个数Opti on ExplicitDim n1%, N2%, n %, i%, st As Stri ngPrivate Sub Comma nd1_Click()Fori = 1 To 10n = In t(R nd(1) * 89 + 0.5) + 10st = st & Str( n)If n Mod 2 = 0 The n N2 = N2 + 1Else n1 = n1 + 1 End If Next iText1.Text = st Text2.Text = N2Text3.Text = n1 End Sub20、判断完数Private Sub Comma nd1
23、_Click() m = Text1.Text For i = 1 To m - 1 If m Mod i = 0 The nsum = sum + ij = j + 1 ReDim Preserve a(j) a(j) = I End If Next i If m = sum The nPicturel.Pri nt m & 是完数,因为” Picturel.Pri nt m;=;For i = 1 To UBound(a) - 1 Picturel.Pri nt a(i); +; Next i Picture1.Pri nt a(i) Else Picture1.Print m & ” 不
24、是完数” End If End Sub21、找鞍点(列最大,行最小)Private Sub Comma nd1_Click()Dim a() As In teger, i As In teger, j As In teger Dim max As Integer, k As Integer, f As Boolean Dim n As Integer, m As Integer, tFor i = 1 To n Print fib(i) Next iPrint End Sub23、求只有三个因子的整数Opti on ExplicitOpti on Base 1Dim fn() As In teger, i As In teger, k As In teger, j As In teger, st As StringPrivate Sub Comma nd1_Click()For i = 10 To 50 k = 0For j = 1 To i -1 If i Mod j = 0 Then k = k
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年导医对初次就诊者的全程心理引导
- AI在药品与医疗器械中的应用
- 2026年CNC加工噪声与粉尘防护培训
- 2026年项目估算与预测技术应用手册
- 矿山隧道凿岩机械 YT23D凿岩机使用范围及技术规格
- 2025湖南省中考物理真题(解析版)
- 2025陕西省中考语文真题(原卷版)
- 2026年学校办公经费精细化管理与审批流程
- 2026年岩土工程师职业发展手册
- 2026年医务科呼吸机临床应用培训总结
- 智能护理技术在手术室护理中的应用
- CRC培训管理制度
- 2024年高考(全国甲卷)英语 阅读七选五真题深层解析+三年真题+题型策略及练习(学生版+解析版)
- 2025至2030中国匹克球球拍行业项目调研及市场前景预测评估报告
- 水电建设工程质量监督检查大纲
- 煤矿新工人安全考试题库及答案解析
- GB/T 24460-2025太阳能光伏照明装置总技术规范
- 智库项目课题申报书
- 学堂在线医学英语词汇进阶(首医)作业单元测验答案
- 2025年山东卷政治参考答案及评分细则
- 地铁行业面试常见问题及答案
评论
0/150
提交评论