湖南省计算机二级考试VB编程题目_第1页
湖南省计算机二级考试VB编程题目_第2页
湖南省计算机二级考试VB编程题目_第3页
湖南省计算机二级考试VB编程题目_第4页
湖南省计算机二级考试VB编程题目_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、l一个数如果刚好与它的因子之和相等,则称完数。求5到100间的完数之和,结果:34sum = 0for n = 5 to 100 s = 0 for i = 1 to n - 1 if n mod i = 0 then s = s + i next i if s = n then sum = sum + nnext nprint sumlijk+kji=1333,其中i,j,k的范围是0到9,求有几组(i,j,k)满足条件,结果:6c = 0for i = 0 to 9for j = 0 to 9for k = 0 to 9if i * 100 + j * 10 + k + k * 100 +

2、 j * 10 + i = 1333 then c = c + 1next k, j, iprint cl宴会上共有1225次握手,每一位参加的人对其他的人都有同样的礼节,那么与会人士有多少,结果:50人数握手数1 02 13 34 6n个人的握手数为:1+2+3+。+n-1=1225,解得n=50l司机开车时里程表读数为一回文数12321公里,开了2小时后里程表又是一个最小回文数,求司机的开车速度。结果:50下一个最小回文数肯定是12421,(12421-12321)/2=50n = 12321do n = n + 1 a = n 10000 b = n 1000 mod 10 c = (n

3、 mod 100) 10 d = n mod 10loop while a <> d or b <> cprint (n - 12321) / 2l好啊好+ 真的好- 真的好啊如果是数字,求该四位数。结果:1098for h = 1 to 9for a = 0 to 9for z = 1 to 9for d = 0 to 9if h * 100 + a * 10 + h + z * 100 + d * 10 + h = z * 1000 + d * 100 + h * 10 + a thenprint h; a; hprint z; d; hprint z; d; h;

4、 aend ifnext d, z, a, hl求500以内含500能被5或9整除的所有自然数的倒数之和?按四舍五入的方式精确到小数点后第二位1.48private sub command1_click()s = 0for i = 1 to 500if i mod 5 = 0 or i mod 9 = 0 then s = s + 1 / inext iprint round(s, 2)end subl求s=1/2+2/3+3/5+5/8的前30项的和(注:该级数从第二项开始,其分子是前一项的分母,'其分母是前一项的分子与分母的和)要求:按四舍五入的方式精确到小数后第二位结果:18.4

5、6private sub command1_click()fz = 1: fm = 2: s = fz / fmfor i = 2 to 30 t = fz: fz = fm: fm = t + fz: s = s + fz / fmnextprint round(s, 2)end subl当m的值为50时,计算:t=1-1/(2*2)-1/(3*3)-1/(m*m) 四舍五入精确到小数点第四位 结果:0.3749private sub command1_click()t = 1for n = 2 to 50t = t - 1 / (n * n)nextprint round(t, 4)end

6、 subl求1 . 50之间所有整数能构成直角三角形的三边的组数。例如;3*3+4*4=5*5.它构成直角三角形,所以3、4、5为一组,但视4、3、5与3、4、5为同一组。结果:20private sub command1_click()n = 0for a = 1 to 50for b = 1 to 50for c = 1 to 50if a 2 + b 2 = c 2 and b > a and c > b then n = n + 1: print a, b, cnext c, b, aprint nend subl求100.900之间相差为12的素数对的对数,(难题),结果

7、:7private sub command1_click()dim a(800)num = 0for i = 100 to 900if isp(i) then a(num) = i: num = num + 1end ifnextfor i = 1 to num if a(i) - a(i - 1) = 12 then n = n + 1nextprint nend subpublic function isp(n)isp = truefor i = 2 to sqr(n) if n mod i = 0 then isp = falsenextend functionl求200,300之间的有

8、奇数个不同因子的最大整数,(在计算因子个数时,包括1和该数本身)结果:289private sub command1_click()for n = 300 to 200 step -1 c = 0 for i = 1 to n if n mod i = 0 then c = c + 1 next i if c mod 2 = 1 then print nnext nend subl求(200,300)有奇数个不同因子的最小整数。(在计算因子个数时,包括1和该数本身),结果:225 for n = 200 to 300 c = 0 for i = 1 to n if n mod i = 0 th

9、en c = c + 1 next i if c mod 2 = 1 then print nnext nl求1000,2000范围内由小到大第100个索数,结果: 1721private sub command1_click()n = 0for i = 1000 to 2000 if isp(i) then n = n + 1 if n = 100 then print i: exit for end ifnext iend subpublic function isp(n)isp = truefor i = 2 to sqr(n) if n mod i = 0 then isp = fal

10、senextend functionl求具有abcd=(ab+cd)2性质的四位数的个数。结果:3n = 0for i = 1000 to 9999 ab = i 100 cd = i mod 100 if i = (ab + cd) 2 then n = n + 1nextprint nl求四位奇数中,各位数之积(积不为0)是60的倍数的数之和。结果:3456254sum = 0for n = 1001 to 9999 step 2 a = n 1000 b = n 100 mod 10 c = n 10 mod 10 d = n mod 10 e = a * b * c * d if e

11、<> 0 and e mod 60 = 0 then sum = sum + nnext nprint sumls=1+1/(1+2)+1/(1+2+3)+1/(1+2+3+n),当n的值为50时,求s得值,结果:1.96078sum = 0s = 0for n = 1 to 50 s = s + n sum = sum + 1 / snextprint suml300,800范围内同时满足以下两个条件的十进制数,(1)其个位数与十位数字之和除以10所得的余数是百位数字;(2)该数是素数,求满足上述条件的最大的三位十进制数。结果:761private sub command1_cl

12、ick()for n = 800 to 300 step -1 b = n 100 s = n 10 mod 10 g = n mod 10 if (g + s) mod 10 = b and isp(n) then print nnextend subpublic function isp(n)isp = truefor i = 2 to sqr(n) if n mod i = 0 then isp = falsenextend functionl斐波那契数列的前二项是1 、1 其后每一项都是前面两项之和,求:10000000以内最大的斐波那契数?9227465a = 1: b = 1: c

13、 = a + bdoa = b: b = c: c = a + bloop while c < 10000000print b注意输出的是b而不是cl一个数如果恰好等于它的所有真因子之和,这个数就称为完数。求(1,100)之间的最大完数?结果:28,(100以内只有6和28两个完数)for n = 100 to 1 step -1 s = 0 for i = 1 to n - 1 if n mod i = 0 then s = s + i next if s = n then print nnextl一个数如果恰好等于它的所有真因子之和,这个数就成为完数。例如:6的真因子为1 2 3 而

14、6=1+2+3 ,因此,6是“完数”。求(8100,8200)之间的完数?结果:8128for n = 8200 to 8100 step -1 s = 0 for i = 1 to n - 1 if n mod i = 0 then s = s + i next if s = n then print nnextl已知:f(0)=f(1)=1 f(2)=0 f(n)=f(n-1)-2f(n-2)+f(n-3),(n>2)求f(0)到f(50)的所有51个值中的最大值?程序设计题:结果:598325dim f(50)f(0) = 1: f(1) = 1: f(2) = 0: max =

15、f(0)for n = 3 to 50 f(n) = f(n - 1) - 2 * f(n - 2) + f(n - 3) if f(n) > max then max = f(n)nextprint maxl已知:a1=1 a2=1/(1+a1) a3=1/(1+a2) a4=1/(1+a3).求a50(按四舍五入的方式精确到小数点后第三位)观察:an=1/(1+an-1),结果:0.618dim a(50) as doublea(1) = 1for n = 2 to 50 a(n) = 1 / (1 + a(n - 1)nextprint a(50)l已知fibonacci数列:1,

16、1,2,3,5,8.它可由下面公式表达:f(1)=1 if n=1 f(2)=1 if n=2 f(n)=f(n-1)+f(n-2) if n>2 试求f(45)值 提示:最好使用递推法求解(用递推法要用好长的时间还可能得不到解,下面是递推法)结果:1134903170private sub command1_click()print f(45)end subpublic function f(n)if n = 1 or n = 2 then f = 1else f = f(n - 1) + f(n - 2)end ifend function最好用下面方法:dim x(45) as l

17、ongx(1) = 1: x(2) = 1for i = 3 to 45 x(i) = x(i - 1) + x(i - 2)nextprint x(45),l有一个三位数满足下列条件(1)此三位数的三位数字各不相同(2)此三位数等于它的各位数字的立方和。试求所有这样的三位数之和(即水仙花数之和),结果:1301sum = 0for b = 1 to 9 for s = 0 to 9 for g = 0 to 9 n = b * 100 + s * 10 + g if b <> s and s <> g and b <> g and n = b 3 + s

18、3 + g 3 then sum = sum + n end ifnext g, s, bprint suml已知s1=2 s2=2+4 s3=2+4+6 s4=2+4+6+8 s5=2+4+6+8+10.求s=s1+s2+s3+s4+s5+.+s20的值,(仔细观察得出:sn=sn-1+2*n),结果:3080sum = 0s = 0for n= 1 to 20 s = s + 2 * n sum = sum + snextprint sum 一l爱因斯坦上楼梯,一次跨2级剩1级,一次跨4级剩3级,一次跨5级剩正好(其腿也太长),求楼梯最少有多少级?同题:韩信点兵,2人一组剩1人,4人一组剩

19、3人,5人一组正好,求这队士兵最少多少人?private sub form_click()s = 1do while s mod 2 <> 1 or s mod 4 <> 3 or s mod 5 <> 0 s = s + 1loopprint send sub二l当n=50时,求下列级数和:s=1/(1*2)+1/(2*3)+1/(n*(n+1)按四舍五入的方式精确到小数点后第四位。结果:0.9804private sub form_click()s = 0for n = 1 to 50 s = s + 1 / (n * (n + 1)next nprin

20、t round(s, 4)end sub三l计算y=1+2/3+3/5+4/7+n/(2*n-1)的值,n=50,要求:按四舍五入的方式精确到小数点后第二位。结果:26.47private sub form_click()y = 0for n = 1 to 50 y = y + n / (2 * n - 1)next nprint round(y, 2)end sub四l水仙花数和。结果是:1301private sub form_click()y = 0for b = 1 to 9 for s = 0 to 9 for g = 0 to 9 n = 100 * b + 10 * s + g

21、if n = b 3 + s 3 + g 3 then y = y + nnext g, s, bprint yend sub五l把一张一元钞票,换成一分、二分和五分硬币,每种至少11枚,有多少种方案?结果:13(同题:百马驮百瓦、百钱买百鸡。)private sub form_click()s = 0for a = 11 to 100 for b = 11 to 50 for c = 11 to 20 if a + b * 2 + c * 5 = 100 then s = s + 1next c, b, aprint send subvb期末范围题总汇 1 求随机10个整数的最大值、最小值、

22、平均值以及和; dim a(1 to 10) private sub command1_click() randomize picture1.print "产生的随机数为:" for i = 1 to 10 a(i) = int(rnd * 99 + 1) picture1.print a(i); next i picture1.print end sub private sub command2_click() dim max, min, ave max = a(1) min = a(1) ave = 0.1 * a(1) for i = 2 to 10 if a(i)

23、> max then max = a(i) if a(i) < min then min = a(i) ave = ave + 0.1 * a(i) next i picture1.print "最大数为:" max picture1.print "最小数为:" min picture1.print "平均数为:" ave end sub 2.求水仙花数 private sub form_click() dim a, b, c as integer 'a(个)b(十)c(百) for a = 0 to 9 for

24、b = 0 to 9 for c = 1 to 9 if a 3 + b 3 + c 3 = a + 10 * b + 100 * c then msgbox 100 * c + 10 * b + a end if next c next b next a end sub 3.百元买百鸡问题; option explicit const a = 5, b = 3, c = 1 private sub form_activate() dim i as integer, j as integer, k as integer, n as integer for i = 1 to 100 for j

25、= 1 to 100 for k = 1 to 100 if i * a + j * b + k * c = 100 then n = n + 1 list1.additem " 公鸡:" & i & " 母鸡:" & j & " 小鸡:" & k end if next: next: next msgbox "共有组合:" & n end sub 求1000以内的所有完数 一个按钮里调用的过程 private sub command1_click() outputw

26、annumber 1000 end sub 4.'求完数的过程 private sub form_click() dim i, j as integer for i = 4 to 100 temp = 1 for j = 2 to i / 2 if i mod j = 0 then temp = temp + j end if next j if temp = i then print i end if next i end sub 5.求各位数字之和 input a:'输入任意数 do b=a mod 10:'取a的末位数 sum=sum+b:'求和 a=a

27、10:'去掉末位数 loop until a=0 print "sum="sum:'输出 end (dim n as string input n for i = 1 to len(n) sum=sum+val(mid(n,i,1) next i print sum) 6.求最小公倍数 private sub form_load() form1.autoredraw = true dim n1%, m1%, m%, n%, r% n1 = inputbox("输入n1") m1 = inputbox("输入m1") i

28、f m1 > n1 then '为了求最小公倍数,增加m,n变量 m = m1: n = n1 else m = n1: n = m1 end if do r = m mod n if r = 0 then exit do m = n n = r loop print n1; "," m1; "的最大公约数为" n print "最小公倍数=", m1 * n1 / n end sub 7.求逆序数(感觉题目类型太多) 8. 级数有限项求和问题(题目类型太多) 9. 求质因子问题 private sub command1

29、_click() dim n as integer, i as integer n = val(inputbox("请输入2的整数:") i = 2 do if n mod i = 0 then print i; n = n i else i = i 1 end if loop while n 1 end sub 10. 字符统计 option base1 option explicit private sub command1_click() dim i as integer,a(26) as integer,n as integer dim s as string*1,

30、strl as string strl=text1 n=len(strl) for i=1 to n s=mid(strl,i,1) if ucase(s)>=”a” and ucase(s)<=”z” then a(asc(ucase(s)-64)+1 end if next i for i=1 to 26 list1.additem chr(64+i) & “:” & a(i) netx i end sub private sub command_click() end end sub 第二大题 1. 判定素数过程 function isprime(num as long) as boolean if num < 2 then isprime = false: exit function dim i as long for i = 2 to sqr(num) if (num mod i) = 0 then isprime = false exit function end if next i isprime = true end function private sub command1_click() dim i as long for i = 1 to 1000 if isprime(i) then pr

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论