《湖南省计算机二级考试VB编程题目汇总.doc》由会员分享,可在线阅读,更多相关《湖南省计算机二级考试VB编程题目汇总.doc(15页珍藏版)》请在金锄头文库上搜索。
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; aEnd IfNext d, z,
4、 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.46Private Sub Command1_C
5、lick()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 SubL求1 . 50之间所有整数能构成直角
6、三角形的三边的组数。例如;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的素数对的对数,(难题),结果:7Private Sub Command1_Click()Dim
7、 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之间的有奇数个不同因子的最大整数,(在计算因子个数时,包括1和该数本身)结
8、果: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 Then c = c + 1 Next i If c Mod 2 =
9、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 = FalseNextEnd FunctionL求具有abcd=(ab+cd
10、)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 0 And e Mod 60 = 0 Then Sum = Sum
11、 + 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_Click()For n = 800 To 300 Step -1 b = n 100
12、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 = a + bDoa = b: b = c: c = a + bLoop While c 2)求f(0)到f(50)的所有51个值中的最大值?程序设计题:结果:598325Dim f(50)f(0) = 1: f(1) = 1: f(2) = 0: Max = 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/(