版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、程序填空1、'功能:要求输入若干学生的成绩,计算平均分和高于平均分的人数,并将这两个数据放入数组的最后。Private Sub Form_Click() Dim mark() As Integer, i%, n%, aver n = InputBox("输入学生的人数") ReDim mark(1 To n) aver = 0 For i = 1 To n mark(i) = Int(Rnd * 101) aver = aver + mark(i) Next i '*SPACE* preserve ReDim 【?】 mark(1 To n + 2)
2、9;增加两个元素,存放平均分和高于平均分的人数,原来的学生成绩仍保留 mark(n + 1) = aver / n mark(n + 2) = 0 For i = 1 To n '*SPACE* If mark(i) > mark(【?】) Then mark(n + 2) = mark(n + 2) + 1 n+1 Next i For i = 1 To n Print "mark(" i; ")=" mark(i) Next i Print "平均分=" mark(n + 1), "高于平均分人数=&quo
3、t; mark(n + 2)End Sub2、功能:以下程序的功能如(图1)。Private Sub Form_Click()Dim a%, b%, c%, d!, x1, x2, p, q, ra = InputBox("请输入a的值")b = InputBox("请输入b的值")c = InputBox("请输入c的值")d = b * b - 4 * a * cp = -b / (2 * a)If d >= 0 Then'*SPACE* If 【?】 Then d>0 r = Sqr(d) / (2 * a)
4、 x1 = p + r x2 = p - r Else x1 = p x2 = p'*SPACE* 【?】 end if Print "x1=" x1, "x2=" x2'*SPACE*【?】 else q = Sqr(-d) / (2 * a) Print "x1=" p; "+" q; "i", "x2=" p; "-" q; "i"End IfEnd Sub3、功能:以下程序用于判断一个正整数(3)是否为素数。Pr
5、ivate Sub Form_Click()n = InputBox("请输入一个正整数(3)")k = Int(Sqr(n)i = 2swit = 0'*SPACE*Do While i <= k And 【?】 swit=0'*SPACE*If 【?】 Then n mod i=0 swit = 1Else'*SPACE* 【?】 i=i+1End IfLoopIf swit = 0 Then Print n; "是一个素数"Else Print n; "不是素数"End IfEnd Sub4、功能:
6、下面的程序段,用于实现在一个nXm的矩阵中,找出值最大的元素所在的行和列,并输出其值及行号和列号。Private Sub Form_Click()Dim mat() As IntegerDim n as integer, m As Integern = Val(InputBox("请输入矩阵的行数")m = Val(InputBox("请输入矩阵的列数")'*SPACE*【?】 ReDim mat(n,m) As IntegerFor i = 1 To n For j = 1 To m mat(i, j) = InputBox("请输入
7、数组元素值") mat(i, j) = Val(mat(i, j) Next jNext iPrint "所建立的矩阵为"For i = 1 To n For j = 1 To m Print mat(i, j); Next j PrintNext iMax = mat(1, 1)For i = 1 To n For j = 1 To m'*SPACE* If 【?】 Then mat(I,j)>max Max = mat(i, j) col = j'*SPACE* 【?】 row=i End If Next jNext iPrintPrin
8、t "矩阵最大的元素的值为:" mat(row, col)Print "它所在的行号为:" row; "列号为:" colEnd Sub5、功能:以下程序段用于实现矩阵转置,即将一个n×m的矩阵的行和列互换Private Sub Form_Click()Const n = 3Const m = 4Dim a(n, m), b(m, m) As IntegerFor I = 1 To n For j = 1 To m a(I, j) = Int(Rnd * 90) + 10 Next j'*SPACE*【?】 next
9、 iFor I = 1 To n For j = 1 To m'*SPACE* 【?】 b(j,i)=a(I,j) Next jNext IPrint "矩阵转置前"For I = 1 To n For j = 1 To m Print a(I, j); Next j'*SPACE* 【?】 printNext IPrint "矩阵转置后"For I = 1 To m For j = 1 To n Print b(I, j); Next j PrintNext IEnd Sub6、下面过程max()用于求3个数中最大值,利用这个过程求5个
10、数中最大值。Private Sub Form_Click()Print "5个数34、124、68、73、352的最大值是:"max1 = max(34, 124, 68)'*SPACE*max1 =【?】 max(max1,73,352)Print max1End SubPublic Function max(ByVal a%, ByVal b%, ByVal c%)'*SPACE*If 【?】 Then a>b m = aElse m = bEnd If'*SPACE*If 【?】 Then m>c max = mElse max =
11、 cEnd IfEnd Function7、功能:以下程序段利用随机函数生成15个10-100之间的整数,然后用选择法将其从小到大排序。Private Sub Form_Click()Const n = 15Dim a(1 To n) As IntegerDim i As Integer, j As Integer, t As Integer, min As IntegerRandomizeFor i = 1 To n'*SPACE* a(i) =【?】 int(rnd*91+10)Next iFor i = 1 To n Print a(i);Next iPrintFor i = 1
12、 To n - 1'*SPACE* 【?】 t=I For j = i + 1 To n If a(j) < a(t) Then t = j Next j'*SPACE* If 【?】 Then t<>i min = a(i): a(i) = a(t): a(t) = min End IfNext iFor i = 1 To n Print a(i);Next iEnd Sub8、功能:下面的程序段用于实现以下功能:利用冒泡法将一组整数从小到大排序。Private Sub Form_Click()Const n = 15Dim a(1 To n) As Int
13、eger, work As BooleanDim i As Integer, j As Integer, x As IntegerRandomizeFor i = 1 To n a(i) = Int(90 * Rnd) + 10Next iFor i = 1 To n Print a(i);Next iPrint'*SPACE*For i = n To 2 【?】 step -1 work = True For j = 1 To i - 1 If a(j) > a(j + 1) Then x = a(j): a(j) = a(j + 1): a(j + 1) = x'*S
14、PACE* 【?】 work=false End If Next j'*SPACE* If work Then 【?】 exit for Next iFor i = 1 To n Print a(i);Next iEnd Sub9、功能:以下程序的功能如(图1)。Private Sub Form_Click()Dim s As Single, m As Integer, p# s = 1 For m = 1 To 10'*SPACE* p=【?】n(m) s = s + 1 / p Next m Print sEnd SubFunction n(k%) p = 1 For m
15、= 1 To k'*SPACE* p =【?】 p*m Next m'*SPACE*【?】 n=pEnd Function10、功能:从键盘输入学生分数,统计学生总人数和各分数段人数,即优秀(90-100)、良好(80-89)、中等(70-79)、及格(60-69)、不及格(60以下)的人数。Private Sub Form_Click()Dim score%, n1%, n2%, n3%, n4%, n5%msg = "请输入分数(-1结束)"msgtitile = "输入数据"score = Val(InputBox(msg, msg
16、title)'*SPACE*While 【?】 score>=0 and score<=100 total = total + 1'*SPACE* Select Case 【?】 score Case Is >= 90 n1 = n1 + 1 Case Is >= 80 n2 = n2 + 1 Case Is >= 70 n3 = n3 + 1 Case Is >= 60 n4 = n4 + 1 Case Else n5 = n5 + 1'*SPACE* 【?】 end selectscore = Val(InputBox(msg,
17、msgtitle)WendPrint n1, n2, n3, n4, n5,totalEnd Sub11、功能:以下程序段用于实现:输入两个正整数m和n,求其最大公因数和最小公倍数。Private Sub Form_Click()Dim a%, b%, num1%, num2%, tempnum1 = InputBox("请输入一个正整数")num2 = InputBox("请输入一个正整数")'*SPACE*If 【?】 Then num1<num2 temp = num1: num1 = num2: num2 = tempEnd Ifa
18、 = num1b = num2'*SPACE*Do While 【?】 b<>0 temp = a Mod b a = b'*SPACE* 【?】 b=tempLoopPrint "最大公因数为:" aPrint "最小公倍数为:" num1 * num2 / aEnd Sub12、功能:利用下面的过程求m!和m*nPrivate Sub Form_Click()Dim m As Integer, n As Integer m = 2 n = 3'*SPACE* 【?】find m,nEnd SubPrivate Su
19、b find(x As Integer, y As Integer) Dim s, i As Integer'*SPACE* 【?】 s=1 For i = 1 To x s = s * i'*SPACE* p=【?】 x*y Next i Print s, pEnd Sub13、功能:以下程序段用于求n!Private Sub Form_Click() Dim sum As Integer, n As Integer n = InputBox("请输入一个正整数") sum = 0 For i = 1 To n'*SPACE* sum =【?】 s
20、um+mul(i) Next i Print sumEnd SubPrivate Function mul(ByVal x As Integer) Dim s As Integer, i As Integer s = 1'*SPACE* For i = 1 To 【?】 x s = s * i Next i'*SPACE* 【?】 mul=sEnd Function14、功能:从键盘上输入一串字符,以"?"结束,统计输入字符中的大、小写字母和数字的个数。Private Sub Form_Click()Dim ch$, n1%, n2%, n3%n1 = 0n
21、2 = 0n3 = 0ch = InputBox("请输入一个字符")'*SPACE*Do While 【?】 ch<>? Select Case ch Case "a" To "z" n1 = n1 + 1'*SPACE* Case 【?】 "A" To "Z" n2 = n2 + 1 Case "0" To "9" n3 = n3 + 1 End Selectch = InputBox("请输入一个字符"
22、)'*SPACE* loop【?】Print n1, n2, n3End Sub15、功能:下面的程序实现:从键盘输入一个数字,将其插入一个有序数组中,插入后的数组仍保持有序。Private Sub Form_Click()Dim a(10) As Integer, x As IntegerFor i = 1 To 8 a(i) = 2 * i - 1 Print a(i);Next iPrintx = InputBox("请输入要插入的整数")'*SPACE*【?】 a(0)=xi = 8Do While a(i) > x'*SPACE* 【
23、?】 a(i+1)=a(i) i = i - 1Loop'*SPACE*If i > 0 Then 【?】 a(i+1)=xFor i = 1 To 9 Print a(i);Next iEnd Sub16、功能:过程suixian可以判断某一个数字是否是水仙花数,利用该过程找出三位数中所有水仙花数。所谓"水仙花数"是指一个3位数,其各位数字立方和等于该数本身。 Private Sub Form_Click()Dim i As IntegerFor i = 100 To 999'*SPACE* 【?】 suixian iNext iEnd SubPub
24、lic Sub suixian(x As Integer)Dim i%, j%, k%'*SPACE*i =【?】 x100j = (x - i * 100) 10k = x - i * 100 - j * 10'*SPACE*If 【?】 Then Print x i3+j3+k3=xEnd Sub17、功能:输入一个数,若大于0,则显示"+";若小于0,则显示 "-";若等于"0",则显示"零"。Private Sub Command1_Click( )x = Val(Text1.Text)Se
25、lect Case x'*SPACE* 【?】 Case Is>0 Label1.Caption = "+" Case Is < 0'*SPACE* 【?】 Label1.Caption = "-"'*SPACE* 【?】 case 0 Label1.Caption = "零" End SelectEnd Sub18、功能:以下程序段用于计算数组中各元素的乘积。Private Sub Command1_Click()'*SPACE* Dim a(1 To 5) 【?】, b%(2 To 10
26、), i%, t1#, t2# As Iinteger For i = 1 To 5 a(i) = i Next i For i = 2 To 10 b(i) = i Next i t1 = tim(a() t2 = tim(b() Print "t1=" t1, "t2=" t2End Sub'*SPACE*Function tim(【?】 As Integer) a() Dim t#, i% t = 1 For i = LBound(a) To UBound(a) t = t * a(i) Next i tim = tEnd Function
27、19、功能:本程序功能为,单击窗体,Form1的输出结果为' A1=10 B1=20' A2=20 B2=10'*SPACE*Public Sub Swap1【?】 x As Integer, ByVal y As Integer) (ByVal Dim t As Integer t = x x = y y = tEnd SubPublic Sub Swap2(x As Integer, y As Integer) Dim t As Integer t = x x = y y = tEnd SubPrivate Sub Form_Click() Dim a As Int
28、eger, b As Integer a = 10 b = 20 '*SPACE* 【?】 a, b Form1.Print "A1=" a, "B1=" b a = 10 b = 20 '*SPACE* 【?】 a, b Form1.Print "A2=" a, "B2=" bEnd Sub20、功能:求表达式s=x/2!+x3/4!+.+x(2n-1)/(2n)!的值,并在窗体上输出。Private Sub Form_Click() Dim x As Single Dim n As Intege
29、r Dim sum As Single x = Val(InputBox("Please input x Value:") n = Val(InputBox("Please input a integer:") '*SPACE* sum = 【?】 Print "s=" sumEnd SubFunction s(n As Integer, x As Single) As Single Dim i As Single, t As Long s = 0 For i = 1 To n t = 1 For j = 1 To 2 * i
30、 '*SPACE* 【?】 Next j '*SPACE* s = s + x (【?】) / t Next iEnd Function21、功能:写出程序运行后,单击窗体,Form1上显示的内容sum 函数的功能为累加求和' isum = 1' isum = 3' isum = 6' isum = 10' isum = 15Private Sub Form_Click() Dim I As Integer, isum As Integer '*SPACE* For I = 1 To 【?】 Swap1 isum = sum(I)
31、 '*SPACE* Form1.Print "isum " 【?】 Swap2 Next IEnd SubPrivate Function sum(n As Integer) Static j As Integer '*SPACE* 【?】 j + n sum = jEnd Function22、功能:程序输出结果为:n=3 x=42 y=9Private Sub Command1_Click() Dim n, x, y As Integer '*SPACE* n = 0: x =【?】: y = 0 1 Do While x < 20
32、9;*SPACE* n = n 【?】 +1 y = x + y x = x * (x + 1) '*SPACE* 【?】 Loop Form1.Print "n=" & Str(n) Form1.Print "x=" & Str(x) Form1.Print "y=" & Str(y)End Sub23、功能:由输入对话框输入n(n必须为大于零且小于30的自然数),' 计算下列表达式的值,并在标签框Label1上显示。' sum=1/2+1/6+ . +1/(k*(k+1) (k<
33、;=n)Private Sub Form_Click() Dim n As Integer, sum As Double, k As Integer n = Val(InputBox("n=", "请输入自然数n(n>0 且n<30)") '*SPACE* Do While n <= 0 【?】 n >= 30 or n = Val(InputBox("n=", "请重输入") Loop sum = 0 k = 0 Do '*SPACE* k =【?】 K+1 sum = s
34、um + 1 / (k * (k + 1) '*SPACE* Loop Until 【?】 K>=n Label1.Caption = "Sum=" + Str(sum) End Sub24、功能: 用户单击命令按钮后,程序将文本框Text1中的文本反转显示,同时在文本框Text2中显示文本框Text1中字符串的个数。Private Sub Command1_Click() If Text1.Text = "" Then Exit Sub Text2.Text = 0 Else '*SPACE* Text1.Text =【?】 (T
35、ext1.Text) MyFun End IfEnd SubPrivate Sub Form_Load() Text1.Text = "" Text2.Text = 0End SubPrivate Function MyFun(s1 As String) As String Dim Pos As Integer Dim Str1 As String Dim intC As Integer Const Sp As String = "" '*SPACE* Pos = Len(【?】) s1 For intC = Pos To 1 Step -1 S
36、tr1 = Str1 & Mid(s1, intC, 1) Next intC '*SPACE* MyFun = 【?】 Str1 Text2.Text = PosEnd Function25、功能:下面的事件过程判断文本框Text1中输入的数所在区间,并在文本框Text2中输出判断结果Private Sub Command1_Click() Dim int1 As Integer4题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) &
37、; "/" & CStr(j) j = i i = i + mNext '*SPACE* 【?】 = Val(Text1.Text) int1 Select Case int1 Case 0 Text2.Text = "值为0" '*SPACE* Case 【?】 1 to 10 Text2.Text = "值在1和10之间(包括1和10)" '*SPACE* Case Is > 【?】 10 Text2.Text = "值大于10" Case Else Text2.Text
38、= "值小于0" End SelectEnd Sub6题 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)程序设计题1、题目:(事件)单击窗体(响应)用输入框输入一自然数,判断是"正数"、"负数或"零",并根据输入的数用消息框显示"正数"、"负数”或"零"。1题n = InputBox("输入一个自然数")
39、If n > 0 Then result = "正数"ElseIf n < 0 Then result = "负数"ElseIf n = 0 Then result = "零"End IfMsgBox "输入的数据" & n & "为:" & result3题Dim i As Integers = 0For i = 1 To 10 s = s + 1 / (i i)NextPrint (s)2、题目:(事件)单击窗体。(响应)求200300之间既能被3整除又能
40、被7整除的数。并求出所有数之和存入变量SUM中2题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、题目:单击窗体。(响应)已知S=1+1/4+1/9+1/16+1/25+1/100,结果输出在窗体上。5题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) =
41、 100) Then Print (CStr(i) Print (CStr(j) Print (CStr(k) n = n + 1 End If Next NextNext4、题目:(事件)单击窗体。(响应)在窗体上打印数列2/1,3/2,5/3,8/5,13/8的前10项,并求其和,将和保存在变量s中。5、题目:(事件)双击窗体。(响应)把一元钞票换成一分、二分和五分的硬币每种至少有一枚),求出其所有的换法,把结果输出在窗体上。将所有的换法的数目存入变量N中6、题目:单击窗体。)求1!+2!+3!+4!+5!并将结果输出到窗体上。结果存入变量S中7题Dim a(9) As IntegerDi
42、m 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)P
43、rint (CStr(aver)7、题目:(事件)单击窗体。(响应)生成一个一维数组(10个数组元素依此为:' 15、23、72、43、96、23、3、65、88、17写程序求出这个数组中的最大值、最小值和平均值,并输出在窗体上。将最大值,最小值,平均值分别存入变量Max,Min,Aver中8、题目:(事件)单击窗体。(响应)在窗体上输出100200之间的所有合数。求出所有数之和存入SUM中所谓合数是指自然数中能被1和本数整除以外,还能被其他数整除的数。9、题目:(事件)单击窗体。(响应)求1020之间所有素数的乘积并输出在窗体上。将结果存入变量L中。10、题目:(事件)单击窗体。(响
44、应)求1 - 1/2 + 1/3 - 1/4 + + 1/99 - 1/100的值。将结果存入变量J中。11、题目: (事件)单击窗体。(响应)如果一个数的真因子之和等于这个数本身,则称这样的数为“完全数”。例如,整数28的真因子为1、2、4、7、11,其和是28。因此28是一个完全数。请编写一个程序,求出500以内最大的完全数。并存入变量SUM中。使用for.next语句完成程序 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 /
45、i End If Next Print j8题 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 sum11题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 N
46、ext j If s = 0 Then Exit For End IfNext iPrint isum=i9题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)12、题目:应用选择法对数组A按升序排列12题Dim i, j, imin, temp As Integer For i = 1 To n -
47、 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、题目:单击窗体。求一个数,它除3余2,除5余3,除7余2,请将满足上面条件的最小数保存到sum变量中。使用for.next语句完成程序。13题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 E
48、nd IfNext i sum = i14、题目:编写函数fun,函数的功能是:判断一个字符是字母字符、数字字符还是其他字符,并做相应的显示。字母字符显示字符串"字母",数字字符显示字符串"数字",其他字符显示字符串"其他",要求使用IF语句来实现。If UCase(n) >= "A" And UCase(n) <= "Z" Then fun = "字母"ElseIf n >= "0" And n <= "9"
49、Then fun = "数字"Else fun = "其他"End IfPrivate 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.Pat
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- DB6111∕T+215-2024+设施火龙果产期调控技术规程
- DB4110T74-2024农田氮磷面源污染源头减控技术规程
- 煤炭业生态环境保护措施考核试卷
- 玉质艺术品的审美标准与评价体系考核试卷
- 森林改培对农村生活质量的提升考核试卷
- DB11∕T 1821-2021 建设项目环境影响评价技术指南 生物药品制品制造
- 物业公司员工培训制度及流程
- 结肠肿瘤课件教学课件
- 产品介绍课件教学课件
- 人事岗课件教学课件
- 八大特殊作业安全试题题库
- 标签打印管理办法及流程
- 五四制青岛版2022-2023五年级科学上册第五单元第19课《生物的栖息地》课件(定稿)
- DB65∕T 3253-2020 建筑消防设施质量检测评定规程
- 四年级上册美术教案15《有创意的书》人教版
- 否定词否定句课件(PPT 38页)
- 水力学第12章 相似理论-2015
- 第7章国际资本流动与国际金融危机
- 藏传佛教英文词汇
- 模拟法庭刑事案例解析
- 人像摄影构图(PPT)
评论
0/150
提交评论