写出下列程序运行结果
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
写出下列程序运行结果:
理解PRINT
A=5:B=3
PRINT A,B,A+B
END
X=9:Y=7
PRINT "X=";X,"Y=";Y
PRINT "X+Y=";X;"+";Y;"=";X+Y END
A=4:B=7
PRINT "C=";A+B*2-A/2
END
理解变量(包括字符串变量)
X=6:Y=0
PRINT X-2,
X=X+7
PRINT “Y=”;X+2
PRINT Y
END
M=12:N=6
X=M/N:Y=M+N
PRINT X,Y
X=X+N:Y=M+X
PRINT X,Y
END
A=7:B=4
A=A+B:B=A-B:A=A-B
PRINT “A=”;A,”B=”;B
END A$=”123”:B$=”321”
C$=A$+B$
PRINT A$;”+”;B$;”=”;C$
END
理解INPUT
INPUT X,Y
C=X*Y
PRINT “C=”;C
END
? 4, 8
INPUT “A,B=”;A,B
D=A+A+B+B
PRINT D
END
A,B=? 2,3
绘图语句
SCREEN 12
LINE (100,100)-(400,300),2,B LINE (100,100)-(400,300),2 END
SCREEN 12
LINE (100,100)-(400,100) LINE –(100,300)
LINE –(100,100)
END
SCREEN 12
CIRCLE (200,200),100
LINE (200,100)-(200,300) LINE (200,200),(300,200)
END
简单函数
A=12.34: B=-5.34: C=0
D=A*A: E=B*B
PRINT ABS(A),ABS(B),ABS(C)
PRINT FIX(A),FIX(B),FIX(C)
PRINT SQR(D),SQR(E)
END
A=3.14: B=A^2: C=-A
D=FIX(A):E=ABS(C):F=SQR(B)
PRINT ABS(D),E,F
END
子字符串函数
A$=”123456789”
L$=LEFT$(A$,4)+MID$(A$,3,3)+RIGHT$(A$,2) PRINT L$
END
A$=”I am a student.”
B$=”I like sing.”
C$=”I often use computer.”
D$=LEFT$(A$,2)+MID$(B$,3,5)+RIGHT$(C$,9) PRINT “D$=”;D$
END
读数置数语句
READ A,B,C
PRINT A,B+C
DATA 3,2,5
END
READ X,Y
PRINT “X=”;X,”Y=”;Y
READ X
PRINT X,Y DATA 3,2,5
END
M=0 : READ A : M=M+A READ B : M=M+B
PRINT M
DATA 21,34,26
END
理解循环语句
FOR I=1 TO 10 STEP 3
PRINT “I=”;I,”I^2=”;I*I NEXT I
END
M=0
FOR A=2 TO 10 STEP 3
M=M+A
NEXT A
PRINT “M=”;M, “P=”;M/3 END
双重循环
FOR A=1 TO 3
FOR B=4 TO 5
PRINT A,B
NEXT B
NEXT A
END
FOR X=6 TO 10 STEP 2
FOR Y=5 TO 3 STEP –2
PRINT X-Y
NEXT Y
NEXT X
掌握IF选择结构语句
INPUT X
IF X>=10 THEN Y=0.5*X ELSE Y=0.4*X PRINT “X=”;X, “Y=”;Y
END
第一次运行:
?12
第二次运行:
?8
A=5: B=6
INPUT C
IF C=A+B THEN
PRINT “RIGHT!”
ELSE
PRINT “WRONG!”
END IF
第一次运行:
?12
第二次运行:
?11
INPUT X
IF X<0 THEN X=-X
PRINT “X=”; X
END
? –12
READ X
FOR I=1 TO 5
READ H
IF H>X THEN X=H
NEXT I
PRINT “MAX=”; X
DATA 2,4,3,2,1,3
FOR I=1 TO 5
READ X, Y IF X>=70 AND Y>=70 THEN PRINT X,Y NEXT I
DATA 78,98,77,66,55,77,78,78,90,90 END
N=0
FOR I=1 TO 5
READ A,B
IF A>B THEN N=N+1
NEXT I
PRINT “N=”; N
DATA 78,98,77,66,55,77,78,78,95,90
子程序:
SUB FM
PRINT “WHO ARE YOU?”
END SUB
SUB ZCX1
PRINT “I am a good boy.”
END SUB
SUB ZCX2
PRINT “I am a good girl.”
END SUB
主程序:
CLS
CALL FM
CALL ZCX1
CALL ZCX2
END
此题的子程序与上一题一样:
主程序:
INPUT N
IF N=1 THEN CALL ZCX1
IF N=2 THEN CALL ZCX2
END
? 1