1、VB条件语句和循环语句测试习题(满分100分)班级 姓名 一、根据程序写运行结果1写出下列程序的运行结果。(5分) Private sub command1_clickX=VAL(text1.text)IF XB THENMAX=_ELSEMAX= ENDIFPRINT MAX=;MAXEnd sub2.求和S=1+3+5+7+99Private sub command1_clickS=0FOR I=1 TO 99 STEP S=_NEXT IPRINT “S=”;SEnd sub3.完善下列程序,使其能求出2+4+6+100之和。Private sub command1_clickFOR I
2、 =_ TO 100 STEP _S= S+I _ IPRINT SEnd sub4从键盘任意输入一个数,判断这个是否是偶数,如果是偶数输出“Y”,否则输出“N”。Private sub command1_clickX=VAL(Inputbox(X= )IF THENPRINT “N”ELSEPRINT “Y”END IFEnd sub5 从键盘输入圆的半径R,输出圆的周长L和面积S。Private sub command1_clickDim R As SingleDim L As Single Dim S As Single R=InputBox(输入半径R ) L=_S=3.14*R*RP
3、rint 圆的周长L= ;LPrint 圆的面积S= ;SEnd sub6. 计算旅客的行李费,收费标准为:20千克以下(包括20千克)不收费,超过20千克的部分每千克收20元。X表示行李重量,Y表示行李费。Private sub command1_click Dim X As Single Dim Y As SingleX=InputBox(输入行李重量) If _ Then Y=0 Else Y=_ End If Print 行李费= ;Y End sub7. 求s=99+97+95+1之和。Private sub command1_clickDim i As IntegerDim s A
4、s Integers=0 For I=99 To _ Step _ s=_Next IPrint S=;S End sub8. 输出100以内(包含100)能被3整除的数。Private sub command1_clickDim I As IntegerI=1Do while If I Mod 3=0 Then Print I End IfI=I+1Loop End sub9.求一元二次方程ax2+bx+c=0的根,要求从键盘输入三个数,判断有无根。有根则输出两根的值分别为X1,X2,无根则输出“无根”Private sub command1_clickA=VAL(InputBox(A= )B=VAL(InputBox(B= )C=VAL(InputBox(C= )D=B*B-4*A*CIF D _ 0 THEN X1=(-B+Sqr(d)/(2*a) X2=_ Print X1=;X1Print X2=;X2ELSE Print 无根End If End sub 2 / 2