循环结构测试题(四)
:选择题
1 :以下()是正确的for….nex结构。
(A) for x=1 to step 10 (B) for x=3 to -3 step -3
next x
(C ) for x=1 to 10
re: …
Next x
If I=10 then goto re
2 :下列循环语句能正常结束循环的是(
(A)I=5
do
I=I+1
Loop until I<0
(C) I=10
do
I=I-1
Loop until I<0
3 :下面程序段的运行结果为( )
for I=3 to 1 step -1
print spc(5-I);
next x
(D) for x=3 to step
3
next y
)
(B) I=1 do
I=I+2
loop until I=10
(D) I=6
do
I=I-2
loop until
I=1
for j=1 to 2*1-1
print “ * n ext j print next I
4下列程序在文本框输入B )“* * ABCD ”四个字符时*窗体上显示D 是* (* *
)
* * *
*****
private sub text1_cha nge() print textl.text; end sub
2:下面程序段显示=i(②
for j=1 to 4
For I=1 to n=n*j
print n
For j=2 j to I Print Next j Next I
(A) ABCD (B)
(D) A
(C ) AABABCABCD
AB 5哪个程序段不能分别正确显示 1!,2!,3!,4!的(
ABC
(A)
二:填空题
1:要使下列 for I=1 to 4 n=1
for j=1 to I n=n*j
F(5<r x l 语句循环执行
print n
for k=(
next
①) (B )
for I=1 to 4 for j=1 to I n=1 n=n*j
20次,循环变量的初值应当是:
print n
n ext i
to -5 step —
ABCD
个“ * ”。
(D) N=1 J=1
Do while j<=4
n=n*j print n j=j+1 loop
30 for j=1 to 12 step 3
40
for k=6 to 2 step —
41 print j,k
42 next k
43 next j
4:以下程序运行后,si,sj,l,j,k的结果分别是(⑤),(©),(⑦),(⑧),(⑨ ),(⑽)
private sub command1_click()
for l=1 to 2
for j=1 to l
sk=0
for k=j to 3
sk=sk+1
next k
sj=sj+1
next j
si=si+1
next l
print si,sj,sk,l,j,k
end sub
5:下面程序运行后输出的结果是((11))
private sub command1_click()
for l=0 to 3
print tab(5*I+1); ” 2”+I; ”2” &I;
next I end sub
6:下面程序运行后输出的结果是((12))
private sub command1_click() a$=”*”;b$= ”$”
for I=2 to 4 if I mod 2=0 then
x$=string(len(a$)+I,b$)
else
x$=string(len(a$)+I,a$)
end if print x$;
next I
end sub
7:执行下面程序,打印结果是((13)) option explicit private sub form_click( ) dim I as integer,j as integer
j=10
for I=1 to j step 2
I=I+1
J=j-I
Next I
Print I,j
End sub
8:输入任意长度的字符串,要求将字符顺序倒置,例如:将输入
ABCDEFG 变换成“ GFEDCBA ”
private sub command1_click()
dim a$,I%,c$
a=inputbox( 输“入字符串”)
n=( (14) )
for I =1 to ( (15))
c=mid(a,I,1)
mid(a,l,1)=( (16))
((17) )=c
next I
print a
end sub
9:找出被3,5,7除,余数为 1 的最小的 5 个正整数。
Private sub command1_click()
Dim countN%,n%
CountN=0
N=1
Do
N=n+1
If ( (18) ) the n
Print n
CountN=countN+1
End if
Loop ( (19))
End sub
10:某次大奖赛,有7 个评委打分,如下程序对一名参加比赛者,输入7个评委的打分分数,去掉一个最高分,一个最低分数,求出平均分为该参赛选手的得分。
Private sub command1_click()
Dim mark!,aver!,I%,max!,min!
Aver=0
For I=1 to 7
Mark=inputbox( 输“入第“ &I& ”位评委的打分”)
If I=1 then
Max1=mark
((20))
else
if mark<min1 then
( ( 21) )
elseif mark>max1 then
( ( 22) ) end if
end if
( ( 23) )
next I
aver=((24) )
print aver
end sub
11:由键盘上输入一个正整数,找出大于或等于该数的第一个质数。
Private sub command1_click( )
Dim m%,x%,tag as Boolean
Tag=false
X=inputbox( 输“入正整数”)
Do while not tag
M=2
Tag=( ( 25) )
Do while tag and (m<(x\2))
If x mod m=0 then ( (26) ) else ( ( 27) )
Loop
If not tag then x=x+1
Loop
Print x
End sub
12:将一个正整数分解为质因数乘机,例如:234=2*3*3*13 private sub command1_click()
dim n%,factor%,first as Boolean n=inputbox(输入一个正整数”) factor=2
first二true
do
do while ( (28))
if first the n
print n; ” 二” factor;
else
print “ * ” ;factor;
end if
((29))
first=false
loop
factor=fact o叶1
loop un til factor> n
end sub
测试题(四)答案)选择题
二)填空题
1: 33
2:10 3: 4,12
4:2,3,2,3,3, 4
5:2 20 3 21 4 22 5 23
6 :**$$$****$$$$$
7:13-16 8:LEN(a),int(n\2),mid(a,n-I+1,1),mid(a,n-I+1,1)
9:n mod 3=1 and n mod 5=1 and n mod 7=1
until countN=5 或while countN<5
10:min1=mark ;min1=mark ;max1=mark aver=aver+mark ;(aver-max1-min1)/5 11:true;tag=true ;m=m+1
12: n mod factor=0 ;n=n\factor。