当前位置:首页 > 第四章 选择结构程序设计(A级)
1,3,5,7,8,10,12: days=31; 4,6,9,11: days=30; 2: days=28 else days:=0; end;
if days<>0 then writeln('days=',days); end.
输入\后,输出结果为days=31。 输入\后,输出结果为days=28。 输入\后,输出结果为无输出。 9、程序清单:
program ex9(input,output); var a,b:integer; begin read(a); case a of
2: b:=pred(a*10); 4: b:=pred(a*20); 6: b:=pred(a*30); else b:=succ(a); end; writeln(b); end.
输入\后,输出结果为19。 输入\后,输出结果为179。 输入\后,输出结果为8。 10、程序清单:
program ex10(input,output); var num:integer; begin
write('num=?'); readln(num); writeln;
write('The weekday ',num,' is '); case num of
0: writeln('Sunday'); 1: writeln('Monday'); 2: writeln('Tuesday'); 3: writeln('Wednesday'); 4: writeln('Thursday'); 5: writeln('Friday'); 6: writeln('Saturday'); end; end.
输入\后,输出结果为The weekday is Sunday。 输入\后,输出结果为The weekday is Wednesday。
完善程序:
1、输入一个小写的英文字母,将其转为大写的英文字母,并将大写的英文字母输出。 样例输入:a 样例输出:A
program ex5_1(input,output); var
sh,ch:char; i:integer; begin readln(ch); i:=ord(ch); if (i>96) and (i<123) then sh:=chr(i-32) else sh:=ch; writeln(sh); end.
2、计算下面函数的值: y=1+x(x>=0) y=1-x(x<0) 样例输入:x=5 样例输出:x=5 y=6
program ex5_2(input,output); var x,y:integer; begin write('x='); read(x);
if x<0 then y:=1-x else y:=1+x; writeln('x=',x); writeln('y=',y); end.
3、超市里卖电池,每个电池8角钱,若数量超过10个,则可打7.5折。 样例输入:num=45 样例输出:total=27.00
program ex5_3(input,output); var num,price,total:real; begin
write('num='); readln(num); price:=0.8;
if num>10 then price:=price*0.75; total:=num*price; writeln('total=',total:0:2); readln end.
4、输入三角形的三个边,判断它是何种类型的三角形.(等边三角形?等腰三角形?一般三角形?) 样例输入1:a,b,c=?25 25 38 样例输出1:Deng Yao San Jiao Xing 样例输入2:a,b,c=?25 25 25 样例输出2:Deng Bian San Jiao Xing program ex5_4(input,output); var a,b,c:integer; begin
write('a,b,c=?'); readln(a,b,c);
if a=b then if a=c then writeln('Deng Bian San Jiao Xing') else writeln('Deng Yao San Jiao Xing') else if b=c then writeln('Deng Yao San Jiao Xing') else writeln('Yi Ban San Jiao Xing'); end.
编写程序:
某车站行李托运费标准是:10千克或10千克以下,收费2.5元,超过10千克的行李,按每超过1千克增加1.5元进行收费。试编一程序,输入行李的重量,算出托运费。 输入样例1:Input zhongliang:5 输出样例1:Tuo yun fei:2.50 输入样例2:Input zhongliang:11 输出样例2:Tuo yun fei:4.00 program ex4_6(input,output); var a,b,c:real; begin
write('Input zhongliang:'); readln(a);
if a>10 then begin b:=a-10; c:=2.5+b*1.5; end else c:=2.5;
writeln('Tuo yun fei:',c:0:2) end.
共分享92篇相关文档