已阅读5页,还剩12页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
编程题1 编写程序在窗体上输出如下图形。Private sub form_click()Dim I,j,k as integerForm1.fontsize=20PrintFor i=1 to 7Print tab(i);For j=1 to 14-(2*i-1)Print “*”;Next jPrint “”; For k=1 to 2*i-1?”$”;Next kPrintNext iEnd sub2 设计一个窗体,输入一个三位整数,将它反向输出。例如输入246,输出642。Private sub command1_click() Dim s,x,y,z,k as integer S=val(text1.text)X=s100Y=s10 mod 10Z=s mod 10K=z*100+y*10+x 或 k=z&y&xLabel1.caption=kEnd sub3求1+1/1!+1/2!+1/3!+1/n! 直到一项小于10-6(用DoLoop语句)Private sub form_click() Dim e as double,t as double Dim I as integerE=1T=1I=1Do while (1/t)=0.000001) T=t*i E=e+1/t I=i+1Loop Form1.fontsize=20 ?eEnd sub4编写程序,在100999三位整数范围内,找出这样的数(水仙花数):该数等于其各数字的立方和。例如:371=33+73+13,即371就是水仙花数。Dim s,I,j,k as integerPrintForm1.fontsize=20 For s=100 to 999I=s100J=s10-i*10 或 j=s10 mod 10K=s mod 10 If s=i*i*i+j*j*j+k*k*k thenMsgbox(“是水仙花”)ElseMsgbox(“不是水仙花”)endifNext sEnd sub5编写程序,求出s=1+(1+2)+(1+2+3)+ +(1+2+3+n)的值。Private sub command1_click()Dim n,I,j as integerDim s,sum as doubleS=0:sum=0N=val(text1.text)For i=1 to nS=s+iSum=sum+sNext iText1.text=sumEnd sub6用递归法求n!。Private function fac(n)as double If n0 then Fac=n*fac(n-1)Else Fac=1End functionPrivate sub command1_click() Dim n as integer,m as integershow N=val(text1.text) If n20 then Msgbox(“重新输入数据”) Exit subEnd ifM=fac(n)Text2.text=format(m,”,”,”)Text1.setfocusEnd sub7求出矩阵中最大元素所在的行和列,输出其值、行号和列号。Private sub command1_click() Dim a(1 to 4,1 to 5)as integer Dim max as integer For i=1 to 4 For j=1 to 5A(I,j)=int(rnd*90+10)+10 Next jNext iMax=a(1,1) For i=1 to 4 For j=1 to 5If maxa(I,j) thenMax=a(I,j)M=iN=jendif Next jPrintNext iPrint”矩阵的最大元素为:”;max,m,nEnd sub8编写一个程序,从键盘输入10个学生成绩,统计最高分、最低分和平均分。Private sub command1_click()Dim mark(10)as integer,avger as integer,max as integerDim min,sum,as integerSum=0For i=1 to 10 Mark(i)=inputbox(“输入”&i&”位同学的成绩”) Sum=sum+mark(i)Next iAver=sum/10Max=0:min=100For i=1 to 10 If maxmark(i) then min=mark(i)Next iPrint “最高分是”;max;”分”Print “最低分是”;min; ”分”Print “平均分是”;aver; ”分”End sub9求一个33矩阵对角线元素之和。Private sub command1_click()Dim a(1to3,1to3)as integerDim I,j ,sum as integer Sum=0 for i=1 to 3for j=1 to 3 a(i,j)=inputbox(“输入数据”)next jnext i for i=1 to 3 sum=sum+a(i,i) next iprint sum10今有n个数,请编程将这些数按由大到小的顺序排列“降序排列” (交换排序)。Dim a(1 to 10)as integerPrivate sub command1_click() Form_loadEnd subPrivate sub command2_click()P=”For i=1 to 9 For j=i+1 to 10 If a(i)a(j) then T=a(i):a(i)=a(j):a(j)=t EndifNext iFor i=1 to 10P=p&str(a(i)&”,”NextLabel2.caption=ltrim(left(p,len(p)-1)End subPrivate sub form_load Dim p as stringRandomizeP=”For i=1 to 10 Do X=int(rnd*91)+10 Yes=0 For j=1 to i-1 If x=a(j) then yes=1:exit forNext jLoop while yes=1A(i)=xP=p&str(i)&”,”Next iLabel1.caption=ltrim(left(p,len(p)-1)Label2.caption=”End dub11今有n个数,请编程将这些数按由大到小的顺序排列“降序排列” (冒泡排序)。Private sub command1_click()Dim a(1to 10)as integerN=inputbox(“请输入一个数”)For i=1 to na(i)=inputbox(“输入数字”)Next iFor i=n to 2 step -1 For j=1 to i-1 If a(j)0 and b0 and c0 and (a+b)c and (a+c)b and (b+c)a thenL=a+b+cS=0.5*lArea=sqr(s*(s-a)*(s-b)*(s-c)ElseMsgbox a & “、” & b”、” & c & “、” & “不能构成三角形!” “、” “注意!”Text1.Text=”Text2.Text=”Text3.Text=”Label6=lLabel8=area Text1.SetfocusEnd IfLabel6=lLabel8=areaEnd SubPrivate sub command2_click()Text1.Text=”Text2.Text=”Text3.Text=”Label6=lLabel8=aText1.SetFocusEnd subPrivate sub command3_click()EndEnd sub13编写求n!的过程或函数,并依此求s=10!+7!8!。Dim a,b,c as integer Private function face (n) as double If n 0 then Face=n * face(n-1) End ifEnd functionPrivate Sub Command1_Click() Dim s as double S=face(a)+face(b)+face(c)Labell.caption = format (s,“!”)End subPrivate sub from_load() a = val(inputbox”请输入第1个数”&“输入a”,0) b = val(inputbox”请输入第2个数”&“输入b”,0) c = val(inputbox”请输入第3个数”&“输入c”,0)End sub14编制判断是否同时被17和37整除的函数。输出10002000之间所有能同时被17和37整除的数。Public Function zheng(x as Integer) As Boolean If x mod 17=0 And x mod 37=0 Then Zheng=Ture Else MsgBox(“不能同时被17和37整除”) End IfEnd FunctionPrivate Sub Command1_click() Dim I As Integer,k As Integer k=1 Print:PrintFor i=1000 to 2000 If zheng(i)=true thenPrint I;K=k+1 End ifIf k mod 10=0 then printNext iEnd sub15编制随机整数Functio过程,输出30个1100之内的随机数。Private Sub Command1_Click() Dim a(1to30)As Integer Form1 Fontsize = 20 For i = 1to30A(i) = sjPrint a(i);If I mod 5=0 then print chr(13)Next iEnd subPublic function sj()as integerRandomize Sj=int(rnd*99+1)endfunction16编写程序,求出s=1+(1+3)+(1+3+5)+ +(1+3+5+2n-1)的值。Private Sub form1_Click()N=inputbox(“请输入N的值”)K=0 s=0Fori=lton K=k+(2*I-1) S=s+kNextiPrint“1+(1+3)+(1+3+2n-1)=”,End Sub 17用随机函数产生10个在1100范围内的随机数,找出最大数和最小数。Dim a(1to 10)as integerPrivate Sub Command1_Click()Dim max as integer,min as integerMin=100:max=0For i=1 to 100If a(i)max then max=a(i)If a(i)min then min=a(i)Next iText1.text=maxText2.text=minEnd subPrivate Sub Command2_Click()Form_loadText1.text=”Text2.text=”End subPrivate Sub form_load()Dim p as stringRomdomizeP=”For i=1 to 10 A(i)=int(rnd*90)+10 P=p&str(a(i)&”,”Next iLabel1.caption=ltim(p,len(p-1)End sub18设计一个简易的文本编辑器,界面如下图所示。要求使用“文件系统”控件选择驱动器、路径、文件类型,打开指定的文件进行编辑,并将编辑后的文件存盘。 Private sub form_load() File1.pattern=”*.exe”End subPrivate sub dir1_changeFile1.path=dir1.pathEnd subPrivate sub drive1_changeDir1.path=drive_driveEnd subPrivate sub file1_click() If rigtht(file1.path,1)”then Text1.text=file1.path&”& file1.filename ElseText1.text=file1.path&file1.filename EndifEnd subPrivate sub command1_clik()Dim int1Int1=sell(text1.text,vbnormalfocus)End sub19设计一个倒计时器,当在文本框中输入一个分钟数,单击命令按钮就开始倒计时,在倒计时结束时,出现信息框“时间到!”的提示。Dim t ,s as integerPrivate Sub Command1_Click()T=val(text1.text)S=t*60Timer1.enabled=trueEnd subPrivate Sub Command2_Click()E
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 辽宁省沈阳市重点中学2025年高一生物第一学期期末质量跟踪监视模拟试题含解析
- 湖北职业技术学院《民航管理信息系统》2024-2025学年第一学期期末试卷
- 浙江省余姚市第四中学2025-2026学年高一上生物期末达标检测试题含解析
- 血液科白血病急性期护理须知
- 苏州工业园区职业技术学院《农化产品高效利用与管理》2024-2025学年第一学期期末试卷
- 风湿免疫科类风湿病综合治疗方案
- 普外科腹腔镜胆囊切除术术后护理规范
- 全科医学科慢性阻塞性肺疾病管理规范
- 肝癌靶向治疗方案
- 社会学实训报告
- 2025广东广州新龙镇招聘农村集体出纳(文员)1人笔试考试参考题库附答案解析
- (2025)儿童脑性瘫痪经颅磁刺激治疗专家共识
- 2025年二级公共营养师考试基础训练题及答案
- 企业生产线优化方案
- 会议室装修工程方案汇报
- 2025年及未来5年中国包头市房地产行业市场供需格局及行业前景展望报告
- 2025年腾讯校招综合素质测评试题及答案
- 2025贵州盐业(集团)黔西南有限责任公司招聘15人笔试考试备考试题及答案解析
- 太仓市国土空间总体规划(2021-2035)
- Q∕GDW 12152-2021 输变电工程建设施工安全风险管理规程
- 财务收支管理系统Excel模板
评论
0/150
提交评论