资源预览内容
第1页 / 共23页
第2页 / 共23页
第3页 / 共23页
第4页 / 共23页
第5页 / 共23页
第6页 / 共23页
第7页 / 共23页
第8页 / 共23页
第9页 / 共23页
第10页 / 共23页
亲,该文档总共23页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
上机操作练习题2016-11(上机考试从117题中随机抽取1题)1某数组有20个元素,其值为随机产生的两位整数。现要求将前10个元素与后10个元素对换。即第1个元素与第20个元素互换,第2个数与第19个元素互换,第10个元素与第11个元素互换。在窗体上输出数组原来各元素的值与对换后各元素的值。Private Sub Command1_Click()Dim i As IntegerDim t As IntegerDim a() As IntegerDim j As IntegerReDim a(20)For i = 1 To 20a(i) = InputBox(请输入第 & i & 个数)Print a(i);Next iPrintPrintPrint 交换元素后:For i = 1 To 19For j = i + 1 To 20If i + j = 21 Thent = a(i)a(i) = a(j)a(j) = tEnd IfNext jPrint a(i);Next iPrint a(20)End Sub*2从数组中删除一个数。先定义一个一维数组,大小、数组的值自定。从键盘上输入一个数,若这个数在数组当中,就把它删除;若这个数不在数组中,提示“该数不在数组中”注意:1)如果数组中存在多个与该数相同的元素,每一个都能删除;2) 能实现多次删除Option ExplicitDim a() As IntegerPrivate Sub Command1_Click()Dim i As IntegerReDim a(9) As IntegerText1.Text = RandomizeFor i = 0 To 9a(i) = Int(Rnd * 15)Text1.Text = Text1.Text & a(i) & vbCrLf vbCrLf是换行,等同于Chr(13)+Chr(10)Next iEnd SubPrivate Sub Command2_Click()Dim i As Integer, m As Integer, flag As Boolean, j As Integer, k As Integerm = InputBox(请输入要删除的数:)flag = FalseDo If a(i) = m Thenj = iflag = TrueFor k = j To UBound(a) - 1a(k) = a(k + 1)Next kReDim Preserve a(UBound(a) - 1)i = i - 1End Ifi = i + 1Loop While i X Then a(i + 1) = a(i) Else a(i + 1) = X Exit For End IfNextIf i = 0 Then a(1) = XFor i = 1 To UBound(a) Print a(i);Next PrintEnd Sub46个评委为4位歌手打分,分数介于1-100之间。去掉一个最高分,一个最低分,求出每位选手的最后得分。将4位歌手得分从高到低排列输出,同时输出该选手的编号。如: 歌手3 95分 歌手 1 87分 歌手 4 80分 歌手 2 70分Option Base 1Dim a(4, 6) As Integer, b(4) As Single, c(4) As IntegerPrivate Sub Command1_Click()Dim m As Integer, i As Integer, j As Integer, k As IntegerText1.Text = Text2.Text = Text3.Text = Text4.Text = For i = 1 To 4 For j = 1 To 6 a(i, j) = InputBox(第 & j & 名评委对第 & i & 名选手的打分:) Next j For k = 1 To 6 If i = 1 Then Text1.Text = Text1.Text & a(i, k) & vbCrLf If i = 2 Then Text2.Text = Text2.Text & a(i, k) & vbCrLf If i = 3 Then Text3.Text = Text3.Text & a(i, k) & vbCrLf If i = 4 Then Text4.Text = Text4.Text & a(i, k) & vbCrLf Next kNext iEnd SubPrivate Sub Command2_Click()Dim i As Integer, j As Integer, max As Integer, min As Integer, sum As Integer, t As SingleFor i = 1 To 4c(i) = iNext iFor i = 1 To 4 二重循环min = a(i, 1)max = a(i, 1)sum = a(i, 1)For j = 2 To 6If a(i, j) max Then max = a(i, j)If a(i, j) min Then min = a(i, j)sum = sum + a(i, j)Next jb(i) = (sum - min - max) / 4 去掉最高分和最低分Next iText6.Text = b(1)Text7.Text = b(2)Text8.Text = b(3)Text9.Text = b(4)For i = 1 To 3 For j = i + 1 To 4 If b(i) m Then t = n: n = m: m = tEnd IfIf n 2 Then MsgBox 请输入大于1的整数For i = n To mIf isprime(i) Then List1.AddItem iEnd IfIf i Mod 10 = 9 Thensum = sum + iEnd If 最后一位是9的所有数据和NextEnd SubPrivate Function isprime(a As Integer) As Boolean 判断素数模块Dim i As Integerisprime = TrueFor i = 2 To CInt(Sqr(a)If a Mod i = 0 Then isprime = False Exit ForEnd IfNext iEnd FunctionPrivate Sub Command2_Click()Open C:DATA.TXT For Output As #1Print #1, sumClose #1Print sumEnd SubPrivate Sub Form_Load()Me.Caption = 素数选择输入Text1.Text = : Text2.Text = Command1.Caption = 输入Command2.Caption = 存盘End Sub补:List1.Style = 1 6. 任意输入一组字符,统计出大写字母多少个,小写字母多少个,数字多少个?要求用过程实现。Private Sub Command1_Click()Dim i As Integer, m As Integer, n As IntegercstringLong = Len(Text1.Text)For i = 1 To cstringLongIf Asc(Mid(Text1.Text, i, 1) = 97 Thenn = n + 1End IfNext iPrint
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号