《计算机二级VB考试题》由会员分享,可在线阅读,更多相关《计算机二级VB考试题(10页珍藏版)》请在金锄头文库上搜索。
1、1、任意输入3种商品价格,若分别购买x,y,z斤,求总后的总价格Private Sub Command1_Click()a = Val(Text1.Text)b = Val(Text2.Text)c = Val(Text3.Text)d = Val(Text4.Text)e = Val(Text5.Text)f = Val(Text6.Text) total = a * b + c * d + e * fText7.Text = totalEnd Sub2、一物体做自由落体运动,求下降t秒时的速度。(重力加速度g=98)Private Sub Command1_Click()t = Val(T
2、ext1.Text)v = 9.8 * tText2.Text = vEnd Sub3、用inputbox函数输入x的值,根据下列分段函数求y值,并用msgbox输出。x2x 0 Theny = (x 人 2 + 9) / xElseIf x -1 And x = 0 Theny = 1Elsey = x * xEnd IfMsgBox y= & yEnd Sub4、任意输入x值,根据分段函数求y值。(用文本框进行输入输出)x , x 0x 2,0 x 10y = 10,10 x 20一 0.5 x + 20,20 x 40Private Sub Command1_Click()x = Val
3、(Text1.Text)If x 0 And x 10 And x 20 And x 10 人(-5) s = s + (-1)人(i - 1) / (2 * i - 1)i = i + 1LoopPrint 4 * sEnd Sub5、公式 s =123n+ + + . +1 + 12 + 13 + 1n + 1求 s 的值,直到最后一项大于 0.9999Private Sub Command1_Click()i = 1Do Until i / (i + 1) 0.9999 s = s + i / (i + 1)i = i + 1LoopPrint sEnd Sub6、利用ex的下述近似公式
4、计算e2(直到最后一项小于10八(-5)为止)x x 2x3x nex 二 1 + . T1!2! 3!n!这里可以看出 x=2Private Sub Command1_Click()p = 1存放阶乘i = 1s = 1存放和Do Until 2 人 i / p 10 人(-5)p = p * is = s + 2 人 i / pi = i + 1LoopPrint sEnd Sub7、 在窗体上打印5行 6列的*,打印出来的图形呈菱形Private Sub Command1_Click()For i = 1 To 5For j = 1 To 6Print *;NextPrintNextEn
5、d Sub8、s =+ . +当 n=10 时,求 s2!3!n!Private Sub Command1_Click()n = Val(Text1.Text)p = 1For i = 2 To n若n=10,直接把n替换成10,前面n的输入去掉p = p * is = s + (i - 1) / pNextPrint sEnd Sub9、任意输入10个数放入数组,要求这10个数是介于100到1000之间的随机正整数.打印出 数组中得到的所有数字.Private Sub Command1_Click()Dim a(1 To 10) As IntegerRandomize用于产生不同的随机数种子
6、,以避免连续产生相同的随机数For i = 1 To 10 a(i) = Int(Rnd() * 90 + 10)Print a(i)NextEnd Sub2、s+3! 34! 4 +1n ! n求s,直到最后一项的值小于10A(-6)Private Sub Command1_Click()i = 3 p = 6放阶乘Do Until 1 / (p - i) b(i) Then n = n + 1n 用于计数NextPrint n=; nEnd Sub4、设计程序,求s=1*(1+2)*(1+2+3)*.*(l+2+3+.+i的值,编程求当n=20时的s值。Private Sub Comman
7、d1_Click()s = 1For i = 1 To 20 p = p + i s = s * pNextPrint sEnd Sub1!2!n!s =+ .5、 输入一个n值,计算1 + 22 + 3 n + 1 + n的值并打印。Private Sub Command1_Click()n = Val(Text1.Text)p = 1p用来放阶乘For i = 1 To np = p * is = s + p / (i + i + 1)NextPrint sEnd Sub2、有2数组,每个数组10个元素,且均已按从大到小顺序排好。编一个程序将这2组数 合并为一组数,并仍按从大到小顺序排列。
8、(提示:合并时可以新建一个含有 20 个元素数 组,每一次比较后把数据放在新数组中)Option Base 1通用声明段Private Sub Command1_Click()Dim c(1 To 20) As Integera = Array(211, 210, 203, 199, 187, 165, 154, 132, 102, 100)b = Array(985, 300, 200, 198, 188, 176, 150, 120, 110, 9)i = 1: j = 1: k = 1Do While i = 10 And j = 10 And k b(j) Thenc(k) = a(i
9、)i = i + 1Elsec(k) = b(j)j = j + 1End Ifk = k + 1LoopIf i 10 ThenFor j = j To 10c(k) = b(j)k = k + 1NextElseIf j 10 ThenFor i = i To 10c(k) = a(i)k = k + 1NextEnd IfFor k = 1 To 20Print c(k);NextPrintEnd Sub编写一个求n!的子程序过程,利用该过程求下列表达式的值:S=1/1! + 1/2! +1/3! + +1/n! 求当 n=10 时 s 的值。 Private Sub Command1_Click()Dim j As Integer, p As LongFor j = 1 To 10Call ff(j, p)s = s