当前位置:首页 > 第四章 选择结构程序设计(A级)
填空题:
1、表达式 not true or true and false的值为false。 2、表达式 ord(false)+5的值为5。 3、表达式 pred(succ(true))的值为true。 4、表达式 5 div 2<(5-2)的值为true。
5、\若A-B不小于C,则将B增加1,否则将B减少1“用Pascal语言可表示为if A-B>=C then B:=B+1 else B:=B-1;。
6、\闰年指年号能被4整除,但不能被100整除,或者年号能被400整除的年\写成Pascal语言表达式为(year mod 4=0) and (year mod 100<>0) or (year mod 400=0)。 7、inc(ord(true))的结果是2。
8、表达式(2<=1) or not(2<10) and (10>4)的结果是false。
9、命题\都是偶数或都是奇数\可表示为(m mod 2=0) and (n mod 2=0) or (m mod 2=1) and (n mod 2=1)。
10、dec(inc(ord(true)))的结果是1。
单项选择题:
1、下面的表达式中,布尔值为true的是4+5 mod 2>4。 (4+5) mod 2>4 '0'>'a' 0>a
2、下列选项中,不是布尔表达式的是5 div 3。 not b
(x>0) or (y>0) 9+4>5+3
3、下面哪一个是布尔变量的标识符?boolean。 true integer real
4、下面条件语句的格式书写不正确的是if 条件 then 语句1; else 语句2。 if 条件 then 语句1
if 条件 then 语句1 else 语句2
5、对于复合语句描述不正确的是begin后面没有符号,中间的语句末尾加\,最后一个语句与end之间必须加\。
复合语句是以begin开始,以end结束,中间包含若干个语句的语句组 复合语句中的end后面可以加\,也可以不加符号
当if语句的then或else后面包括多个语句时,必须写成复合语句,else与它前面的语句之间不能含\6、对下面描述case语句不正确的是case与of之间的表达式可以是有序类型,也可以是实型。 case语句是多分支选择语句,它所包含的语句1~n中只有一个语句被执行 case语句的end之前的语句可以省略\,end后面有无\都允许 case语句中的常数表是用逗号分隔的常数 7、下列选项中不是逻辑运算符的是end。 not or and
8、Pascal不允许输入的数据类型是布尔型。 实型 字符型 整型
9、17 mod 4<>0的结果是true。 0 1 false
10、对于布尔型数据的描述不正确的是布尔型数据,不可以利用write或writeln语句输出。 Pascal语言允许利用赋值语句为布尔型变量提供数据 Pascal语言不能使用read语句输入布尔型数据 Pascal语言可以用布尔型符号常量来定义常量 判断题:
1、下面条件(if)语句的嵌套书写格式不正确。(对) if a<0 then if b>0 then writeln else
writeln('b'); else
writeln('a');
2、字符型、布尔型、整型、实型都是有序数据。(错) 3、not、and、or、end都是单目运算符。(错) 4、表达式true and not false的值是TRUE。(对) 5、pred(ord(true))的结果是0。(对)
6、and、or、+、-既是双目运算符,又是单目运算符。(错)
7、“若A不大于B,则打印B ”用Pascal语言表示为if Ab then x:=1; if a
将上述两个if语句合并成一个if语句,下面书写格式正确。(对) if a>b then x:=1
else if a
9、dec(ord(false))的结果是-1。(对)
10、pred(true)函数值的类型为boolean。(对)
阅读程序: 1、程序清单:
program ex1(input,output); var a:integer; begin readln(a);
if a mod 2=0 then writeln(a,'->oushu') else writeln(a,'->jishu'); end.
输入\288”后,输出结果为1288->oushu。 2、程序清单:
program ex2(input,output); var x,y:real; begin write('x='); read(x);
if x<0 then y:=1-x else y:=1+x; writeln('x=',x,' ':4,'y=',y); end.
输入\后,输出结果为x=15
x= 1.5000000000E+01 y= 1.6000000000E+01。 输入\后,输出结果为x=-2
x=-2.0000000000E+00 y= 3.0000000000E+00。 3、程序清单:
program ex3(input,output); var a,b:boolean; begin
a:=true;b:=false; writeln(a); writeln(b); end.
输出结果为TRUE FALSE。 4、程序清单:
program ex4(input,output); var
a:integer; b:boolean; begin readln(a);
if a mod 2=0 then b:=true else b:=false; writeln(b); end.
输入\后,输出结果为TRUE。 输入\后,输出结果为FALSE。 5、程序清单:
program ex5(input,output); var a,b,c:integer; begin write('a=');
readln(a); write('b='); readln(b); if a
writeln('a=',a,' b=',b); end
else writeln('a=',a,' b=',b); end.
输入\后,输出结果为a=45 b=85 a=85 b=45。 6、程序清单:
program ex6(input,output); var k,x:integer; begin
k:=2;x:=0;
if (k<=10) and (k>0) then if k>5 then if k>8 then x:=0 else x:=1 else if k>2 then x:=3 else x:=4; writeln(x:1); end.
输出结果为4。 7、程序清单:
program ex7(input,output); var a,b:integer; begin
readln(a,b);
if a>0 then if b>0 then writeln('a*b=',a*b) else writeln('a div b=',a div b) else writeln(a,'<=0'); end.
输入\后,输出结果为a*b=12。 输入\后,输出结果为a div b=-2。 输入\后,输出结果为-5<=0。 8、程序清单:
program ex8(input,output); var month,days:integer; begin
readln(month); case month of
共分享92篇相关文档