




已阅读5页,还剩35页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
计算机基础教学网http:/ email: ccbs2011 1 /= 声明:本篇所列 程序代码, 未经过上机调试, 故不承诺绝对正确,仅供参考。 所列 ex x-y, 指教材 x 章,第 y 道编程题。 教材指:vb 语言程序设计教程,宁爱军,人民邮电出版社,isbn: 978-7-115-19360-5 其他相关资料,请查阅 计算机基础教学网http:/ 联系 email:ccbs2011 作者:宁爱军 /= ex4-1 option explicit private sub command1_click() dim ras integer dim has integer dim las single dim s as single dim s2 as single dim vas single dim v2 as single r = val(text1.text) h = val(text2.text) l = 2 * 3.14 * r s = 3.14 * r * r s2 = 4 * 3.14 * r * r v = 3.14 * r * r * h v2 = 4 * 3.14 * r * r * r / 3 text3.text = str(l) text4.text = str(s) text5.text = str(s2) text6.text = str(v) text7.text = str(v2) end sub ex4-2 option explicit private sub command1_click() dim fas integer dim cas single f = val(text1.text) c = 5 / 9 * (f - 32) 计算机基础教学网http:/ email: ccbs2011 2 text2.text = str(c) end sub ex4-3 option explicit private sub command1_click() dim nas integer n = log(2) / log(1 + 0.008) print n= s end sub ex5-1 option explicit private sub command1_click() form2_8.fontsize = 16 dim mas integer m = val(inputbox(输入一个整数) if m mod 6 = 0 and m mod 9 = 0 and m mod 14 = 0 then print m a; b=; b; c=; c; d=; d if a b then t = a a = b b = t end if if a c then t = a a = c c = t end if if a d then t = a a = d d = t end if if b c then t = b b = c c = t end if if b d then t = b b = d d = t end if if c 0 then y = log(a) + log(b) elseif a 0and b down then if down = 50 then all = down * 80 + (up - down) * 60 else all = down * 90 + (up - down) * 60 end if else if up = 50 then all = up * 80 + (down - up) * 45 else all = up * 90 + (down - up) * 45 end if end if 计算机基础教学网http:/ email: ccbs2011 8 text3.text = str(all) end sub ex5- 补充(1)224/9=22+22+42 option explicit private sub command1_click() form3_30.fontsize = 16 dim ias integer, mark as integer dim a as integer,b as integer,c as integer i=text1.text a=i mod 10 b= i 10 mod 10 c=i 100 if a2+b2+c2=i 9 then print i end if end sub ex5-补充(2)守形数 option explicit private sub command1_click() form3_30.fontsize = 16 dim ias integer i=text1.text if i*i mod 100 = i then print i;是守形数 end i end sub ex5-补充(3)真分数 option explicit private sub command1_click() dim mas integer, n as integer m=text1.text n=text2.text a= m%10 计算机基础教学网http:/ email: ccbs2011 9 b=m /10 c=n%10 d=n/10 if a=d and c*m=b*n then print m ;/; n;是真分数 end i end sub ex5-补充(4)运费 option explicit private sub command1_click() dim p as double,w as double,s as double,d as double,t as double p=text1.text w=text2.text s=text3.text if s=250 then d=0 elseif s=500 then d=0.02 elseif s=1000 then d=0.05 elseif s=2000 then d=0.08 elseif s=3000 then d=0.10 else d=0.15 end if 方法 2 select case s case is = 0.000001 s = s + 1 / i i = i + m m = m + 1 wend print s=; s end sub ex6-7 option explicit private sub command1_click() form3_22.fontsize = 16 dim nas long dim pi as single n = 1 pi = 2 while n 1000 pi = pi * (2 * n * 2 * n) / (2 * n - 1) * (2 * n + 1) n = n + 1 wend print pi=; pi end sub ex6-8 option explicit private sub command1_click() form3_23.fontsize = 16 dim ias integer dim s as long dim tas long s = 0 t = 1 for i = 1to10 t = t * i s = s + t 计算机基础教学网http:/ email: ccbs2011 13 next print s=; s end sub ex6-9 option explicit private sub command1_click() form3_24.fontsize = 16 dim xas integer dim nas integer dim resultas single dim s as double n = 1 result = 1 s = 1 x = val(inputbox(输入 x 的值) while n 100 s = s * x / n result = result + s n = n + 1 wend print result=; result end sub ex6-10 option explicit private sub command1_click() form3_25.fontsize = 16 dim aas integer dim bas integer dim cas integer for n=100 to 999 a=n mod 10 b=n 10 mod 10 c=n100 if n = a 3 + b 3 + c 3 then print n end if next 方法 2: for a = 1to9 计算机基础教学网http:/ email: ccbs2011 14 for b = 0to9 for c = 0to9 if 100 * a + 10 * b + c = a 3 + b 3 + c 3 then print 100 * a + 10 * b + c end if next next next end sub ex6-11 option explicit private sub command1_click() form3_26.fontsize = 16 dim nas integer dim aas integer dim ias integer dim bas long dim s as long n = inputbox(输入 n) a = inputbox(输入 a) b = a for i = 1ton s = s + b b = b * 10 + a next print s=; s end sub ex6-12 option explicit private sub command1_click() form3_27.fontsize = 16 dim ias integer dim jas integer dim s as integer for i = 1to1000 s = 0 for j = 1toi - 1 if i mod j = 0 then s = s + j end if 计算机基础教学网http:/ email: ccbs2011 15 next if i = s then print i end if next end sub ex6-13 option explicit private sub command1_click() form3_28.fontsize = 16 dim ias integer dim jas integer for i = 1to5 for j = 1to5 - i print ; next j for j = 1to5 print *; next j print next i end sub ex6-14 option explicit private sub command1_click() form3_29.fontsize = 16 dim xas integer dim yas integer dim zas integer for x = 0to9 for y = 0to12 for z = 0to36 if x + y + z = 36and 4 * x + 3 * y + z / 2 = 36 then print x=; x; y=; y; z=; z end if next next next end sub 计算机基础教学网http:/ email: ccbs2011 16 ex6-15 option explicit private sub command1_click() form3_30.fontsize = 16 dim s as integer dim xas integer dim ias integer dim aveas single s = 0 for i = 1to20 x = val(inputbox(输入) s = s + x next ave = s / 20 print s=; s; ave=; ave end sub ex6-补充(2)打印所有守形数 private sub command1_click() form3_30.fontsize = 16 dim s as double,n as long s=0 t=1 n=1 do s=s+t; loop while() if i*i mod 100 = i then print i end if end sub ex6-补充(3)打印所有守形数 private sub command1_click() form3_30.fontsize = 16 dim ias integer for i = 10to99 if i*i mod 100 = i then print i end i next i 计算机基础教学网http:/ email: ccbs2011 17 end sub ex6-补充(4) 勾股数 32+42=52 ,xyz option explicit private sub command1_click() form3_30.fontsize = 16 dim aas integer,b as integer,c as integer for a = 1to100 for b=1 to 100 for c=1 to 100 if a=80 then n8=n8+1 else if mark=70 then n7=n7+1 else if mark=60 then n6=n6+1 else n0=n0+1 end if next print n9,n8,n7,n6,n0 end sub ex7-1 option explicit private sub command1_click() form4_13.fontsize = 16 dim a(10)as integer dim ias integer dim sum as integer dim aveas single randomize (time) for i = 1to10 a(i) = int(rnd * 9 + 1) next i for i = 1to10 print a(i); next i sum = 0 for i = 1to10 sum = sum + a(i) next i ave = sum / 10 print print sum= next i sum = 0 count = 0 for i = 1to10 if a(i) mod 2 = 0 then sum = sum + a(i) count = count + 1 end if next i ave = sum / count print print ave= next i for i = 1to10 2 t = a(i) a(i) = a(11 - i) a(11 - i) = t next i print for i = 1to10 print a(i); next i end sub ex7-4 option explicit private sub command1_click() form4_16.fontsize = 16 text1.fontsize = 16 dim a(100)as integer dim ias integer dim count1 as integer dim count2 as integer randomize (time) for i = 1to100 a(i) = int(rnd * 100 + 1) next i for i = 1to100 text1.text = text1.text next i for i = 1to10 b(i) = a(i) next i print print 数组 b for i = 1to10 print b(i); next i end sub ex7-7 option explicit private sub command1_click() form4_19.fontsize = 16 dim a(5)as integer dim ias integer dim sum as integer dim b(10)as integer randomize (time) for i = 1to5 a(i) = int(rnd * 10 + 1) next i 计算机基础教学网http:/ email: ccbs2011 23 for i = 1to5 b(i) = int(rnd * 10 + 1) next i print 数组 a for i = 1to5 print a(i); next i print print 数组 b for i = 1to5 print b(i); next i for i = 1to5 b(5 + i) = a(i) next i print print 连接后数组 b for i = 1to10 print b(i); next i end sub ex7-8 option explicit private sub command1_click() text1.fontsize = 16 text2.fontsize = 16 dim a(100)as integer dim ias integer, jas integer dim delas integer dim countas integer dim n as integer count = 100 randomize (time) for i = 1tocount a(i) = int(rnd * 10) next i 计算机基础教学网http:/ email: ccbs2011 24 for i = 1tocount text1.text = text1.text next i ins = inputbox(insert) for i = 10to1 step -1 if a(i) ins then a(i + 1) = a(i) else a(i + 1) = ins exit for end if next i if i = 0 then a(i + 1) = ins end if print for i = 1to11 print a(i); next i end sub ex7-10 计算机基础教学网http:/ email: ccbs2011 26 option explicit private sub command1_click() text1.fontsize = 16 dim f(20)as integer dim ias integer for i = 3to20 if i=1 then f(i) = 1 elseif i=2 then f(i)= 2 * i - 1 else f(i) = f(i - 1) + 2 * i end if next i for i = 1to20 text1.text = text1.text 计算机基础教学网http:/ email: ccbs2011 27 next j print next i max = a(1, 1) min = a(1, 1) for i = 1to10 for j = 1to10 if max a(i, j) then min = a(i, j) end if next j next i print max= next j print next i sum = 0 计算机基础教学网http:/ email: ccbs2011 28 for i = 1to10 sum = sum + a(i, i) next i print sum= next j print next i for i = 1to10 for j = 1to10 row(i) = row(i) + a(i, j) next j next i for j = 1to10 for i = 1to10 column(j) = column(j) + a(i, j) next i 计算机基础教学网http:/ email: ccbs2011 29 next j for i = 1to10 text1.text = text1.text end if next end sub ex8-1 option explicit function v1(ras integer)as single dim vas single v = 4 / 3 * 3.14 * r * r * r v1 = v end function function v2(ras integer, h as integer)as single dim vas single v = 3.14 * r * r * h v2 = v end function private sub command1_click() dim ras integer dim has integer dim vas single dim vv as single 计算机基础教学网http:/ email: ccbs2011 32 form5_11.fontsize = 16 r = val(inputbox() h = val(inputbox() v = v1(r) vv = v2(r, h) print v1=; v print v2=; vv end sub ex8-2 option explicit function fact(mas integer) as boolean dim aas integer, bas integer, cas integer dim ras boolean a = m 100 b = (m mod 100) 10 c = m mod 10 if a 3 + b 3 + c 3 = m then r = true else r = false end if fact = r end function private sub command1_click() dim ias integer dim ras boolean form5_12.fontsize = 16 for i = 100to999 r = fact(i) if r = true then print i end if next i end sub ex8-3 option explicit function prime(mas integer) as boolean dim ias integer dim ras boolean 计算机基础教学网http:/ email: ccbs2011 33 for i = 2tom - 1 if m mod i = 0 then exit for end if next i if i = m then r = true else r = false end if prime = r end function private sub command1_click() dim ias integer dim ras boolean form5_13.fontsize = 16 for i = 100to999 r = prime(i) if r = true then print i end if next i end sub ex8-4 option explicit function f(n as integer, xas single) as double dim sas double dim ias integer s = 1 for i = 1to2 * n - 1 s = s * x / i next for i = 1ton - 1 s = s * (-1) next f = s end function function mysin(x as single) as double dim sas double, tas double, n as integer 计算机基础教学网http:/ email: ccbs2011 34 s = 0 n = 1 t = x do s = s + t n = n + 1 t = f(n, x) loop while abs(t) 0.00001 mysin = s end function private sub command1_click() dim ias integer dim ras boolean form5_13.fontsize = 16 print mysin(3.1415926 / 2) end sub ex8-7 一维数组做函数参数 option explicit sub sort(a()as integer , n as integer) dim ias integer, jas integer, tas integer for i = 1ton-1 for j = 1ton - i if a(j) a(j + 1) then t = a(j) a(j) = a(j + 1) a(j + 1) = t end if next j next i end sub function ave(a()as integer , n as integer) as single dim s as integer dim average as single dim ias integer s = 0 for i = 1ton s = s + a(i) next i average = s / n 计算机基础教学网http:/ email: ccbs2011 35 ave = average end function function max(a()as integer, nas integer) as integer dim ias integer max = a(1) for i = 2ton if max a(i) then max = a(i) end if next i end function sub inputarr(a()as integer, n as integer) dim i as integer randomize (time) for i = 1ton a(i) = int(rnd * 10 + 1) next i end sub sub printarr(a()as integer, nas integer) dim i as integer randomize (time) for i = 1ton print a(i) ; next i end sub private sub command1_click() dim a(10)as integer dim average as single dim max as integer form5_17.fontsize = 16 call inputarr(a(),10) print 排序前 callprintarr(a(),10) sort a(),10 print: print 排序后 callprintarr(a(),10) average = ave(a(),10) print average=; average 计算机基础教学网http:/ email: ccbs2011 36 print max=; max(a(),10) end sub ex8- 补充:f(x) option explicit function f(x as single)as single dim y as single if x0 then y=x else if x a(i, j) then m = a(i, j) end if next j next i min = m end function function max(a()as integer,m as integer, n as ingeger)as integer 最大值 dim mas integer dim ias integer, jas integer m = a(1, 1) for i = 1tom for j = 1ton if m a(i, j) then m = a(i, j) end if next j next i max = m end function function sum(a()as integer,m as integer, n as inge
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年中国EVA鞋材数据监测报告
- 2025年中国2.9-二甲基喹吖啶酮数据监测研究报告
- 2025至2030年中国龙韵石砖市场分析及竞争策略研究报告
- 2025至2030年中国陶瓷棺市场分析及竞争策略研究报告
- 2025至2030年中国铅合金产品市场分析及竞争策略研究报告
- 2025至2030年中国花泥树脂市场分析及竞争策略研究报告
- 2025至2030年中国线控工程车市场分析及竞争策略研究报告
- 2025至2030年中国矫形胸托市场分析及竞争策略研究报告
- 2025至2030年中国瓦楞针市场分析及竞争策略研究报告
- 2025至2030年中国滑片泵市场分析及竞争策略研究报告
- 棉印染清洁生产审核报告
- 板鞋竞速竞赛规则
- GB 6722-2014爆破安全规程
- 校企合作项目立项申请表(模板)
- 六旋翼无人机的设计(毕业设计)
- 假货鉴定报告
- 艺术概论:第八章综合艺术
- 云南省临沧市各县区乡镇行政村村庄村名居民村民委员会明细及行政区划代码
- 新人教版九年级物理全册知识点总结(课堂笔记)
- DB13T 5519.7-2022 轨道交通AFC系统线网技术要求 第7部分:数据接口
- 驻戈壁某部队糖尿病流行病学调查
评论
0/150
提交评论