完整版VB循环结构测试题及答案.docx
《完整版VB循环结构测试题及答案.docx》由会员分享,可在线阅读,更多相关《完整版VB循环结构测试题及答案.docx(8页珍藏版)》请在冰豆网上搜索。
完整版VB循环结构测试题及答案
循环结构测试题(四)
一:
选择题
1:
以下()是正确的for….next结构。
(A)forx=1tostep10(B)forx=3to–3step-3
…..…..
nextxnextx
(C)forx=1to10(D)forx=3tostep3
re:
….……
Nextxnexty
IfI=10thengotore
2:
下列循环语句能正常结束循环的是()
(A)I=5(B)I=1
dodo
I=I+1I=I+2
LoopuntilI<0loopuntilI=10
(C)I=10(D)I=6
dodo
I=I-1I=I-2
LoopuntilI<0loopuntilI=1
3:
下面程序段的运行结果为()
forI=3to1step–1
printspc(5-I);
forj=1to2*I-1
print“*”;
nextj
print
nextI
(A)
4下列程序在文本框输入“ABCD”四个字符时,窗体上显示的是()
privatesubtext1_change()
printtext1.text;
endsub
(A)ABCD(B)
(C)AABABCABCD
5哪个程序段不能分别正确显示1!
2!
3!
4!
的()
二:
填空题
1:
要使下列For语句循环执行20次,循环变量的初值应当是:
fork=(①)to–5step–2
2:
下面程序段显示(②)个“*”。
ForI=1to5
Forj=2toI
Print“*”;
Nextj
NextI
3:
下列第40句共执行了(③)次,第41句共执行(④)次。
30forj=1to12step3
40fork=6to2step–2
41printj,k
42nextk
43nextj
4:
以下程序运行后,si,sj,I,j,k的结果分别是(⑤),(⑥),(⑦),(⑧),(⑨),(⑽)
privatesubcommand1_click()
forI=1to2
forj=1toI
sk=0
fork=jto3
sk=sk+1
nextk
sj=sj+1
nextj
si=si+1
nextI
printsi,sj,sk,I,j,k
endsub
5:
下面程序运行后输出的结果是(⑾)
privatesubcommand1_click()
forI=0to3
printtab(5*I+1);”2”+I;”2”&I;
nextI
endsub
6:
下面程序运行后输出的结果是(⑿)
privatesubcommand1_click()
a$=”*”;b$=”$”
forI=2to4
ifImod2=0then
x$=string(len(a$)+I,b$)
else
x$=string(len(a$)+I,a$)
endif
printx$;
nextI
endsub
7:
执行下面程序,打印结果是(⒀)
optionexplicit
privatesubform_click()
dimIasinteger,jasinteger
j=10
forI=1tojstep2
I=I+1
J=j-I
NextI
PrintI,j
Endsub
8:
输入任意长度的字符串,要求将字符顺序倒置,例如:
将输入“ABCDEFG”变换成“GFEDCBA”
privatesubcommand1_click()
dima$,I%,c$
a=inputbox(“输入字符串”)
n=(⒁)
forI=1to(⒂)
c=mid(a,I,1)
mid(a,I,1)=(⒃)
(⒄)=c
nextI
printa
endsub
9:
找出被3,5,7除,余数为1的最小的5个正整数。
Privatesubcommand1_click()
DimcountN%,n%
CountN=0
N=1
Do
N=n+1
If(⒅)then
Printn
CountN=countN+1
Endif
Loop(⒆)
Endsub
10:
某次大奖赛,有7个评委打分,如下程序对一名参加比赛者,输入7个评委的打分分数,去掉一个最高分,一个最低分数,求出平均分为该参赛选手的得分。
Privatesubcommand1_click()
Dimmark!
aver!
I%,max!
min!
Aver=0
ForI=1to7
Mark=inputbox(“输入第“&I&”位评委的打分”)
IfI=1then
Max1=mark
(⒇)
else
ifmark((21))
elseifmark>max1then
((22))
endif
endif
((23))
nextI
aver=((24))
printaver
endsub
11:
由键盘上输入一个正整数,找出大于或等于该数的第一个质数。
Privatesubcommand1_click()
Dimm%,x%,tagasBoolean
Tag=false
X=inputbox(“输入正整数”)
Dowhilenottag
M=2
Tag=((25))
Dowhiletagand(m<(x\2))
Ifxmodm=0then((26))else((27))
Loop
Ifnottagthenx=x+1
Loop
Printx
Endsub
12:
将一个正整数分解为质因数乘机,例如:
234=2*3*3*13
privatesubcommand1_click()
dimn%,factor%,firstasBoolean
n=inputbox(“输入一个正整数”)
factor=2
first=true
do
dowhile((28))
iffirstthen
printn;”=”;factor;
else
print“*”;factor;
endif
((29))
first=false
loop
factor=factor+1
loopuntilfactor>n
endsub
测试题(四)答案
一)选择题
1
2
3
4
5
6
7
8
9
10
11
12
B
C
B
C
B
二)填空题
1:
33
2:
10
3:
4,12
4:
2,3,2,3,3,4
5:
220321422523
6:
**$$$****$$$$$
7:
13-16
8:
LEN(a),int(n\2),mid(a,n-I+1,1),mid(a,n-I+1,1)
9:
nmod3=1andnmod5=1andnmod7=1
untilcountN=5或whilecountN<5
10:
min1=mark;min1=mark;max1=mark
aver=aver+mark;(aver-max1-min1)/5
11:
true;tag=true;m=m+1
12:
nmodfactor=0;n=n\factor