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