浙江省计算机二级vb上机试题题库
二、编程题:
1 判断一个数是否是素数。 Private sub form_click()
Dim x as integer,I as integer X=text1
For i=2 to sqr(x) ? If x mod i=0 then exit for Next i
If i>sqr(x) then Text2=”x是素数” Else
Text2=”x不是素数” Endif Endsub
2、 求两个任意自然数的最大公约数。 Private sub form_click()
Dim m as integer,n as integer,I as integer,r as integer m=text1 R=m mod n Do while r<>0
M=n N=r
R=m mod n
n=text2
Loop
Text2=str(n) End sub
3、 随机生成10个两位正整数,将其中的奇数和偶数分别显示在list1和list2中 。 Private sub form_click()
Dim a(1 to 10) as integer,I as integer For i=1 to 10
A(i)=int(rnd*90+10) Next i
If a(i) mod 2=1 then Else
List2.additem str(a(i)) Endif
第 1 页 共 8 页
List1.additem str(a(i))
For i=1 to 10
4、判断一个数是否是回文数。 Private sub form_click()
5求两个自然数的最小公倍数。 Private sub form_click()
Dim m as integer ,x as integer,y as integer,flg as Boolean X=text1:y=text2 Flg=false Do until flg
m=m+x
If m mod y=0 then
Flg=true Ensif
Dim I as integer,s as string S=text1
For i=1 to len(s)\\2
If mid(s,I,1)<>mid(s,len(s)-i+1,1) then exit for Next i
If i>len(s)\\2 then Else
Print s & ”不是回文数” Endif
Print s & ”是回文数” Next i
End sub
End sub
Loop Text2=str( m)
End sub
注:还可用先求最大公约数,再求最小公倍数的方法。
6 从键盘接收一个字符,判断其是否是大写字母、小写字母、数字或其他字符。 Private sub form_click()
Dim x as string x = Text1
Select Case x
Case \ To \ Text2 = \是大写字母\ Case \ To \
Text2 = \是小写字母\ Case \ To \ Text2 = \是数字\ Case Else
第 2 页 共 8 页
Text2 = \是其他字符\
7判断一个三位正整数是否是水仙花数。 Private sub form_click()
8任意生成10个两位正整数,将这10个数的和显示在text1中,平均值显示在text2中。 Private sub form_click()
9求出斐波那契数列的前18项,并按顺序将他们显示在窗体上。斐波那契数列的递推公式如下: Private sub form_click()
10求100以内的偶数和,将结果显示在窗体上。 Private sub form_click()
Dim fb(1 to 18) as integer,I as integer Fb(1)=1:fb(2)=1 For i=3 to 18
Fb(i)=fb(i-1)+fb(i-2) Next i
For i=1 to 18
Print fb(i); Next i
Dim I as integer,x as integer ,s as integer S=0
For i=1 to 10
X=int(rnd*90+10) S=s+x
Dim a as integer,b as integer,c as integer,x as integer X=val(text1) B=(x-a*100)\\10 C=x-a*100-b*10
If x=a^3+b^3+c^3 then Else
Text2=str(x)+”不是水仙花数” Endif
Text2=str(x)+”是水仙花数” End select End sub
A=x\\100
End sub
Next i Text1=str(s) Text2=str(s/10)
End sub
End sub
第 3 页 共 8 页
11任意生成10个两位正整数,使用选择法对其进行升序排序。 Private sub form_click()
12求6!,将阶乘结果显示在窗体上。 Private sub form_click()
13求100以内的奇数和,并将结果显示在窗体上。 Private sub form_click()
Dim s as integer,I as integer S=0
For i=1 to 100 step 2
S=s+i Next i Print s
Dim I as integer,t as long T=1
For i=1 to 6
T=t*i Next i Print t
Dim a(10) as integer,I as integer,j as integer For i=1 to 10
A(i)=int(rnd*90+10) Next i
For j=i+1 to 10
If a(i)>a(j) then
T=a(i):a(i)=a(j):a(j)=t Endif
Dim I as integer,s as integer S=0
For i=2 to 100 step 2 Next i Print s
S=s+i
End sub
For i=1 to 9
Next j
Next i
For i=1 to 10
Print a(i); Next i
End sub
End sub
第 4 页 共 8 页