VB程序设计考试题库——考试专用(9页).doc
-VB程序设计考试题库考试专用-第 9 页程序设计题1、题目:(事件)单击窗体(响应)用输入框输入一自然数,判断是"正数"、"负数或"零",并根据输入的数用消息框显示"正数"、"负数”或"零"。2、题目:(事件)单击窗体。(响应)求200300之间既能被3整除又能被7整除的数。并求出所有数之和存入变量SUM中3、题目:单击窗体。(响应)已知S=1+1/4+1/9+1/16+1/25+1/100,结果输出在窗体上。4、题目:(事件)单击窗体。(响应)在窗体上打印数列2/1,3/2,5/3,8/5,13/8的前10项,并求其和,将和保存在变量s中。5、题目:(事件)双击窗体。(响应)把一元钞票换成一分、二分和五分的硬币每种至少有一枚),求出其所有的换法,把结果输出在窗体上。将所有的换法的数目存入变量N中6、题目:单击窗体。)求1!+2!+3!+4!+5!并将结果输出到窗体上。结果存入变量S中7、题目:(事件)单击窗体。(响应)生成一个一维数组(10个数组元素依此为:' 15、23、72、43、96、23、3、65、88、17写程序求出这个数组中的最大值、最小值和平均值,并输出在窗体上。将最大值,最小值,平均值分别存入变量Max,Min,Aver中8、题目:(事件)单击窗体。(响应)在窗体上输出100200之间的所有合数。求出所有数之和存入SUM中所谓合数是指自然数中能被1和本数整除以外,还能被其他数整除的数。9、题目:(事件)单击窗体。(响应)求1020之间所有素数的乘积并输出在窗体上。将结果存入变量L中。10、题目:(事件)单击窗体。(响应)求1 - 1/2 + 1/3 - 1/4 + + 1/99 - 1/100的值。将结果存入变量J中。1题n = InputBox("输入一个自然数")If n > 0 Then result = "正数"ElseIf n < 0 Then result = "负数"ElseIf n = 0 Then result = "零"End IfMsgBox "输入的数据" & n & "为:" & result2题Dim i As IntegerFor i = 201 To 300 If (i Mod 3) = 0) And (i Mod 7) = 0) Then Print (CStr(i) sum = sum + i End IfNextPrint sum3题Dim i As Integers = 0For i = 1 To 10 s = s + 1 / (i i)NextPrint (s)4题Dim i, j, k, m As Integers = 0 :i = 2:j = 1For k = 1 To 10 s = s + i / j m = j Print (CStr(i) & "/" & CStr(j) j = i i = i + mNext5题Dim i, j, k As IntegerFor i = 1 To 100 For j = 1 To 50 For k = 1 To 20 If (i + 2 * j + k * 5) = 100) Then Print (CStr(i) Print (CStr(j) Print (CStr(k) n = n + 1 End If Next NextNext6题 Dim i, j, k As IntegerFor i = 1 To 5 k = 1 For j = 1 To i k = k * j Next s = s + kNextPrint (CStr(s)7题Dim a(9) As IntegerDim i, s As Integera(0) = 15:a(1) = 23:a(2) = 72a(3) = 43:a(4) = 96:a(5) = 23a(6) = 3:a(7) = 65:a(8) = 88a(9) = 17:max = a(0):min = a(0)s = 0For i = 0 To 9 If a(i) > max Then max = a(i) End If If a(i) < min Then min = a(i) End Ifs = s + a(i)Nextaver = Int(s / 10)Print (CStr(max)Print (CStr(min)Print (CStr(aver)8题 Dim i, j, s As IntegerFor i = 100 To 200 For j = 2 To Sqr(i) If (i Mod j) = 0 Then Print (CStr(i) sum = sum + i Exit For End If NextNextPrint sum9题Dim i%,j%,b As Booleanl = 1:b = FalseFor i = 10 To 20 For j = 2 To i - 2 If i Mod j = 0 Then b = True End If Next If b = False Then l = l * i End If b = FalseNextPrint Str(l)10题Dim i As Integer For i = 1 To 100 If i Mod 2 = 1 Then j = j + 1 / i ElseIf i Mod 2 = 0 Then j = j - 1 / i End If Next Print j11、题目: (事件)单击窗体。(响应)如果一个数的真因子之和等于这个数本身,则称这样的数为“完全数”。例如,整数28的真因子为1、2、4、7、11,其和是28。因此28是一个完全数。请编写一个程序,求出500以内最大的完全数。并存入变量SUM中。使用for.next语句完成程序 12、题目:应用选择法对数组A按升序排列13、题目:单击窗体。求一个数,它除3余2,除5余3,除7余2,请将满足上面条件的最小数保存到sum变量中。使用for.next语句完成程序。14、题目:编写函数fun,函数的功能是:判断一个字符是字母字符、数字字符还是其他字符,并做相应的显示。字母字符显示字符串"字母",数字字符显示字符串"数字",其他字符显示字符串"其他",要求使用IF语句来实现。Private Function fun(n As String) As String'*Program*'* End *End FunctionPrivate Sub Form_Load() Show Print fun("A") Print fun("9") Print fun("&") NJIT_VBEnd SubPrivate Sub NJIT_VB() Dim i As Integer Dim l As Integer Dim a(10) As String * 1 Dim fIn As Integer Dim fOut As Integer fIn = FreeFile Open App.Path & "in.dat" For Input As #fIn fOut = FreeFile Open App.Path & "out.dat" For Output As #fOut For i = 1 To 10 Line Input #fIn, a(i) Print #fOut, fun(a(i) Next Close #fIn Close #fOutEnd Sub15、题目:编写函数fun,函数的功能是:根据一个百分制成绩mark(整数),显示对应五级制的评定。条件如下:'mark大于等于90显示"优秀"'mark小于90且大于等于80显示"良好"'mark小于80且大于等于70显示"中等"'mark小于70且大于等于60显示"及格"'mark小于60显示"不及格"'要求使用IF语句来实现。Private Function fun(mark As Integer) As String'*Program*'* End *End FunctionPrivate Sub Form_Load() Show Print fun(90) NJIT_VBEnd SubPrivate Sub NJIT_VB() Dim i As Integer Dim s As String Dim a(10) As Integer Dim fIn As Integer Dim fOut As Integer fIn = FreeFile Open App.Path & "in.dat" For Input As #fIn fOut = FreeFile Open App.Path & "out.dat" For Output As #fOut For i = 1 To 10 Line Input #fIn, s a(i) = Val(s) Print #fOut, fun(a(i) Next Close #fIn Close #fOutEnd Sub16、题目:编写函数fun,函数的功能是:当x的初值为10,每年增长率为千分之八,计算多少年以后x的值能达到y,并显示所需年数的值(变量名必须为n)。'要求使用Do While . Loop语句来实现。Private Function fun(y As Single) As LongDim x As Single, n As Long'*Program*'* End *End FunctionPrivate Sub Form_Load() Show Print fun(15) NJIT_VBEnd SubPrivate Sub NJIT_VB() Dim i As Integer Dim a(10) As String Dim fIn As Integer Dim fOut As Integer fIn = FreeFile Open App.Path & "in.dat" For Input As #fIn fOut = FreeFile Open App.Path & "out.dat" For Output As #fOut For i = 1 To 10 Line Input #fIn, a(i) Print #fOut, Trim(Str(fun(Val(a(i) Next Close #fIn Close #fOutEnd Sub17、题目:编写函数fun,函数的功能是:求从m到n的乘积并显示,'如:m为2,n为4时,显示"24"'存储连乘的乘积的变量必须为Product'要求使用For语句来实现。Private Function fun(m As Integer, n As Integer) As LongDim Product As Double, t As IntegerIf m > n Then t = m: m = n: n = t'*Program*'* End *End FunctionPrivate Sub Form_Load() Show Print fun(4, 2) NJIT_VBEnd SubPrivate Sub NJIT_VB() Dim i As Integer Dim a(10) As String Dim fIn As Integer Dim fOut As Integer fIn = FreeFile Open App.Path & "in.dat" For Input As #fIn fOut = FreeFile Open App.Path & "out.dat" For Output As #fOut For i = 1 To 10 Step 2 Line Input #fIn, a(i) Line Input #fIn, a(i + 1) Print #fOut, Trim(Str(fun(Val(a(i), Val(a(i + 1) Next Close #fIn Close #fOutEnd Sub18、题目:编写函数fun,函数的功能是:判断一个数是否为素数。并显示相应提示。如:该数为素数时,显示"素数";该数为非素数时,显示"非素数"'要求使用For语句来实现,用布尔型变量flag作为该数是否为素数的标志,注意:不得使用Goto语句。Private Function fun(m As Long) As StringDim flag As Boolean'*Program*'* End *End FunctionPrivate Sub Form_Load() Show Print fun(225) NJIT_VBEnd SubPrivate Sub NJIT_VB() Dim i As Integer Dim a(10) As String Dim fIn As Integer Dim fOut As Integer fIn = FreeFile Open App.Path & "in.dat" For Input As #fIn fOut = FreeFile Open App.Path & "out.dat" For Output As #fOut For i = 1 To 10 Step 1 Line Input #fIn, a(i) Print #fOut, fun(Val(a(i) Next Close #fIn Close #fOutEnd Sub Next Close #fIn Close #fOutEnd Sub19、题目:编写函数fun,函数的功能是:求1100以内能被m整除或能被n整除的数的总和并显示。如:'m为15,n为11时,显示"810",'存储总和的变量必须为Sum,'要求使用For语句来实现。Private Function fun(m As Integer, n As Integer) As LongDim Sum As Long'*Program*'* End *End FunctionPrivate Sub Form_Load() Show16题x = 10n = 0Do While x < y x = x * 1.008 n = n + 1Loopfun = n Print fun(15, 11)19 题Sum = 0For i = 1 To 100 If i Mod m = 0 Or i Mod n = 0 Then Sum = Sum + i End IfNext ifun = Sum NJIT_VBEnd SubPrivate Sub NJIT_VB() Dim i As Integer15题If mark >= 90 Then fun = "优秀"ElseIf mark >= 80 Then fun = "良好"ElseIf mark >= 70 Then fun = "中等"ElseIf mark >= 60 Then fun = "及格"Else fun = "不及格"End If Dim a(10) As String20题Dim s, i As Integer For i = 2 To n - 1 If n Mod i = 0 Then s = s + i End If Next Fun = s Dim fIn As Integer Dim fOut As Integer fIn = FreeFile Open App.Path & "in.dat" For Input As #fIn fOut = FreeFile Open App.Path & "out.dat" For Output As #fOut For i = 1 To 10 Step 2 Line Input #fIn, a(i) Line Input #fIn, a(i + 1) Print #fOut, Trim(Str(fun(Val(a(i), Val(a(i + 1) Next Close #fIn Close #fOutEnd Sub20、题目:编写函数fun,函数的功能是:计算并输出给定整数n的所有因子之和(不包括1与自身)。规定n的值不大于1000? 例如:n的值为855时,应输出704。21、题目:编写函数fun其功能是:判断一个整数w的各位数字平方之和能否被5整除 , 可以被5整除则返回1 , 否则返回022、题目:编写函数fun其功能是:根据整型形参m,计算如下公式的值:' y=1/5+1/6+1/7+1/8+1/9+1/10.+1/(m+5)求:函数中用到的中间变量必须声明为Single类型。11题Dim i As Integerdim s as integerFor i = 500 To 1 Step -1 s = i For j = i - 1 To 1 Step -1 If i Mod j = 0 Then s = s - j End If Next j If s = 0 Then Exit For End IfNext iPrint isum=i12题Dim i, j, imin, temp As Integer For i = 1 To n - 1 imin = i For j = i + 1 To n If a(imin) > a(j) Then imin = j Next j temp = a(i) a(i) = a(imin) a(imin) = temp Next i13题Dim i As Integer For i = 2 To 1000 If i Mod 3 = 2 And i Mod 5 = 3 And i Mod 7 = 2 Then Print i Exit For End IfNext i sum = i14 题If UCase(n) >= "A" And UCase(n) <= "Z" Then fun = "字母"ElseIf n >= "0" And n <= "9" Then fun = "数字"Else fun = "其他"End If15 题 If mark>=90 then Fun=优秀Elself mark >=80 thenFun=良好Elseif mark>=70 then Fun=中等Elseif mark>=60 thenFun=及格Else Fun=不及格16题x = 10n = 0Do While x < y x = x * 1.008 n = n + 1Loopfun = n17题Product = 1For i = m To n Product = Product * iNext ifun = Product18题 flag = TrueFor i = 2 To m - 1 If m Mod i = 0 Then flag = FalseNext iIf flag Then fun = "素数"Else19 题Sum = 0For i = 1 To 100 If i Mod m = 0 Or i Mod n = 0 Then Sum = Sum + i End IfNext i20题Dim s, i As Integer For i = 2 To n - 1 If n Mod i = 0 Then s = s + i End If Next21题 Dim k As Integer, s As Integer Do s = s + (w Mod 10) * (w Mod 10) w = Int(w / 10) Loop While w <> 0 If s Mod 5 = 0 Then k = 1 Else k = 0 End If fun = k22题Dim y As Double Dim i As Integer For i = 0 To m y = y + 1 / (i + 5) Next Fun = y