365文库
登录
注册
2

VB上机试题

265阅读 | 11收藏 | 12页 | 打印 | 举报 | 认领 | 下载提示 | 分享:
2
VB上机试题第1页
VB上机试题第2页
VB上机试题第3页
VB上机试题第4页
VB上机试题第5页
VB上机试题第6页
VB上机试题第7页
VB上机试题第8页
VB上机试题第9页
VB上机试题第10页
VB上机试题第11页
VB上机试题第12页
福利来袭,限时免费在线编辑
转Pdf
right
1/12
right
下载我编辑的
下载原始文档
收藏 收藏
搜索
下载二维码
App功能展示
海量免费资源 海量免费资源
文档在线修改 文档在线修改
图片转文字 图片转文字
限时免广告 限时免广告
多端同步存储 多端同步存储
格式轻松转换 格式轻松转换
用户头像
Echo 上传于:2024-05-24
129:单击窗体。求出100以内所有素数的和,并将结果输出到窗体上,并存入所给变量SUM中 Dim j As Integer Dim k As Integer Dim b As Integer b = False For i = 2 To 100 b = False j = Int(Sqr(i)) For k = 2 To j If i Mod k = 0 Then b = True End If Next If b = False Then Sum = Sum + i End If Next Print Sum 130:求200~300之间既能被3整除又能被7整除的数。并求出所有数之和存入变量SUM中 Dim i As Integer For i = 201 To 300 If i Mod 3 = 0 And i Mod 7 = 0 Then Print i Sum = Sum + i End If Next Print Sum 131:已知S=1+1/4+1/9+1/16+1/25+…+1/100,结果输出在窗体上 Private Sub Form_Click() Dim s As Single Dim I as integer S =0 For I =1to 10 S= s+1/(i^2) Next Print (s) End Sub 132:在窗体上打印数列2/1,3/2,5/3,8/5,13/8…的前10项,并求其和。 Private Sub Form_Click() Dim s As Single Dim i, j, k, m as Integer S =0 I = 2 J = 1 For k = 1 to 10 M = j Print (cstr (i)) & "/" & cstr(j) J =i I =i+m S =s+i/j next End Sub 133: 一球从100米高度自由落下,每次落地返回,原高度的一半,求第10次落地时,共经过多少米?并将结果在窗体上输出。 Private Sub Form_Click() Dim s As Single Dim j , I as integer S = 0 J =100 For I =2 to 10 J = j / 2 S = s + 2 *j Next S =100 +s Print (cstr(s)) End Sub 134: s=20+21+22+…+263,求s的值,并将结果存储到变量S中。 Dim i As Integer i = 20 While i <= 263 s = s + i i = i + 1 Wend Print (CStr(s)) 136: 求出具有如下特点的四位数字,它的平方根恰好就是它中间的两位数字,例如,2500开平方为50,恰为2500的中间两位,找出所有这样的四位数。并求出这两个数字的和存入SUM中 Dim i As Integer Dim j As Integer For i=1000 to 9999 j=Val (Mid (Trim (Str (i) ) ,2,2 ) ) If j ^ 2 = i then Print i sum = sum + i End if Next 137:把一元钞票换成一分、二分和五分的硬币(每种至少有一枚),求出其所有的换法,把结果输出在窗体上。将所有的换法的数目存入变量N中 Dim I,j,k as integer For i=1 to 100 For j=1 to 50 For k=1 t0 20 If ((i+2*j+k*5)=100) Then Print(CStr(i)) Print(CStr(j)) Print(CStr(k)) n = n + 1 End if Next Next Next 138:公鸡3元1只,母鸡5元1只,小鸡一元3只,怎样用100元买。100只鸡。把结果输出到窗体上。将答案数存放在变量N中 Dim i as integer Dim j as integer Dim k as integer For i = 1 to 20 '母鸡 For j = 1 to 33 ' 公鸡 For k = 3 to 100 ' 小鸡 If ( ( k mod 3 ) = 0 ) and ( ( i *5+j*3+k / 3) = 100 ) and ( ( i +j +k =100) Print (cstr(i)) Print (cstr(j) Print (cstr(k)) N = n +1 End if Nxet Next Next 139:编写代码功能如(图1)。将结果存入变量S中。 Dim i As Integer For i = 1 To 10 s = s + i * i Next Print (CStr(s)) 140:编写代码功能如(图1)。将结果存入变量S中 Dim i as integer S = 1 For i = 1 to 10 S = s * i * i Next Print (cstr(s)) 141: 求1!+2!+3!+4!+5!并将结果输出到窗体上。结果存入变量S中 Dim i, j, k, s As Integer For i = 1 To 5 k = 1 For j = 1 To i k = k * j Next s = s + k Next Print (CStr(s)) 142: 编写程序求10×11×12+11×12×13+…+15×16×17的结果,并将结果输出到窗体上。将结果存入变量M中 Private Sub Form_Click() Dim m As Long Dim i, j as integer Dim s as long For i = 10 to 15 S =1 For j =i to i+2 s=s*j Next m = m+s Next Print (cstr(m)) End Sub 143: 生成一个一维数组(10个数组元素依此为:15、23、72、43、96、23、3、65、88、17),写程序求出这个数组中的最大值、最小值和平均值,并输出在窗体上。将最大值,最小值,平均值分别存入变量Max,Min,Aver中 Dim a(9) as integer Dim i , s as integer a(0) = 15 a(1) = 23 a(2) = 72 a(3) = 43 a(4) = 96 a(5) = 23 a(6) = 3 a(7) = 65 a(8) = 88 a(9) = 17 Max = a(0) Min = a(0) S = 0 Fot i = 0 to 9 If a(i) > max then Max = a(i) End if If a(i) < min then Min = a(i) End if S = s + a(i) Next Aver = int(s / 10) Print (cstr(max)) Print (cstr(min)) Print (cstr(aver)) 144:在窗体上输出100~200之间的所有合数。求出所有数之和存入SUM中 Dim i as integer Dim j as integer Dim s as integer For j = 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 Next Next Print sum 146::单击窗体。求50以内所有偶数的和,并在窗体上输出出来。将结果存入变量S中 Dim i As Integer For i = 2 To 50 If (i Mod 2) = 0 Then s = s + i End If Next Print (CStr(s)) 147:求出50以内所有奇数的和。将结果存入变量SUM中 Dim i as integer For i = 1 to 50 If i mod 2 = 1 then Sum = sum +1 End if Next Print sum 148:求10~20之间所有素数的乘积并输出在窗体上。将结果存入变量L中 Dim i as integer Dim j as integer Dim b as boolean l = 1 b = false For i = 10 to 20 For j = 2 to i - 2 If i mod j = 0 then b = ture End if Next If b = false then l = l * i End if b = false Next Print Str (l) 149:求1!+2!+3!+……+10!的值,并在窗体上输出。结果存入变量L中 Dim i as integer Dim s as long Dim j as integer S =1 For i =1 to 10 S =s *i l = l +s Next Print str (l) 150:求1 - 1/2 + 1/3 - 1/4 + …… + 1/99 - 1/100的值。将结果存入变量J中 Dim i as integer For i 1 to 100 If i mod 2 =1 then J = j + 1 / i Elself I mod 2 =0 then J = j - 1 / i End if Next Print j 151:求1+2+3+……+100的值,并把结果输出在窗体上。结果存入变量SUM中 Dim i As Integer For i = 1 To 100 Sum = Sum + i Next Print Sum 152:求1+2+3+5+8+13+……前20项的和,并将结果在窗体上输出。将结果存入变量SUM中 Dim i as integer Dim j(1 to 20) as integer For i = 1 to 20 If i < 3 then J(i) = i Else J(i) = j(i-1) + j(i-2) End if Sum = sum +j(i) Next Print sum 153:求100以内奇数的和,并将结果输出在窗体上。将结果存入变量SUM中 Dim i as integer For i = 1 to 100 If i mod 2 =1 then Sum = sum + i End if Next Print sum 154:求100以内偶数的和,并将结果输出在窗体上。将结果存入变量SUM中 Dim i as integer For i = 1 to 100 if i mod 2 = 0 then Sum = sum +i End if Next Print sum 155:求1+5+10+15+……+500的和,并将结果输出到窗体上。将结果存入变量SUM中 Dim i As Integer For i = 1 To 500 If i Mod 5 = 0 Then Sum = Sum + i End If Next print sum 156:求3+6+9+12+15+18+……+300的和,并将结果输出到窗体上。将结果存入变量 SUM中 Dim i As Integer For i = 3 To 300 If i Mod 3 = 0 Then Sum = Sum + i End If Next print sum 158:求数列1+3+3+9+27+……前6项的和,并将结果输出到窗体上。将结果存入变量SUM中 Dim i As Integer Dim j(1 To 6) As Integer For i = 1 To 6 If i < 3 Then j(i) = 3 ^ (i - 1)
tj