假设邮局规定寄邮件时若每件重量在1公斤以内(含1公斤),按1.5元计算邮费,如果超过1公斤时,其超出部分每公斤加收0.8元。请编程序计算邮件收费。
var
m : real;
q : real;
begin
readln(m);
if m<=1 then
begin
q:=m*1.5;
end;
if m>1 then
begin
q:=(m-1)*0.8+1.5;
end;
writeln('You need pay $',q);
readln;
end.
输入三个正整数,若能用这三个数作为边长组成三角形,就计算并输出该三角形的面积,否则输出Can't。(组成三角形的条件为:任意两边之和大于第三边)
label 1;
var
a,b,c: integer;
S,r: real;
begin
1:
writeln('Enter a,b,c');
readln(a,b,c);
if (a+b>c)and(a+c>b)and(b+c>a) then
begin
r:=(a+b+c)/2;
s:=sqrt(r*(r-a)*(r-b)*(r-c));
writeln('Square is ',s);
readln();
end
else
begin
writeln('Can not');
goto 1;
end;
readln();
end.
输入一个三位数的整数,将数字位置重新排列,组成一个尽可大的三位数。例如:输入213,重新排列可得到尽可能大的三位数是321。
label 1;
var
q,a,b,c:integer;
begin
writeln('Input Q');
readln(q);
a:=q div 100;
b:=q mod 100;
c:=b mod 10;
b:=b div 10;
{
// now we have a,b,c
if (a>b>c) then writeln('Output :',a,b,c);
if (a>c>b) then writeln('Output :',a,c,b);
if (b>a>c) then writeln('Output :',b,a,c);
if (b>c>a) then writeln('Output :',b,c,a);
if (c>a>b) then writeln('Output :',c,a,b);
if (c>b>a) then writeln('Output :',c,b,a);
//error
}
if (a>b) then
begin
if (b>=c) then writeln(a,b,c);
if (b<c)and(c<=a) then writeln(a,c,b);
if (c>a) then writeln(c,a,b);
goto 1;
end;
if (b>a) then
begin
if(a>=c) then writeln(b,a,c);
if(a<b)and(c<=b) then writeln(b,c,a);
if(c>b) then writeln(c,b,a);
goto 1;
end;
if (a=b) then
begin
if(c>=b) then writeln(a,c,b);
if(c<b) then writeln(a,b,c);
goto 1;
end;
1:
readln;
end.
输入一个整数,打印出它是奇数还是偶数。
var
a:integer;
begin
write('Input A :');readln(a);
if((a mod 2)<>0) then writeln('Not');
if((a mod 2)=0) then writeln('Yes');
readln();
end.
某服装公司为了推销产品,采取这样的批发销售方案:凡订购超过100 套的,每套定价为50元,否则每套价格为80元。编程由键盘输入订购套数,输出应付款的金额数。
var
a : longint;
m : longint;
begin
write('Input Number :');readln(a);
if (a>100) then m:=a*50;
if (a>0)and(a<=100) then m:=a*80;
write('Money is :',m);
readln;
end.
从键盘读入一个数,判断它的正负。是正数,则输出“+”,是负数,则输出“-”。
label 1;
var
x : real;
begin
1:
write('Please Input X:');
readln(x);
if x <> 0 then
begin
if x > 0 then writeln('+');
if x < 0 then writeln('-');
end
else
begin
writeln ('Sorry You Can''t Input 0, try again');
goto 1;
end;
readln;
end.
判断两个数a,b,输出较大数的平方值。
label 1;
var
a,b : real;
begin
1:
write('Input a and b please');
readln(a,b);
if a<>b then
if a>b then writeln(sqr(a))
else writeln(sqr(b))
else
begin
writeln('Sorry a can''t be same as b, try again');
goto 1;
end;
readln;
end.
某市的士费起步价8元,可以行使3公里。3公里以后,按每公里1.6元计算,输入的士的公里数,请你计算顾客需付费多少元?
label 1;
var
m,l,t: real;
begin
1:
write('Enter L');
readln(l);
if l>0 then
begin
if l<=3 then
begin
m:=3;
writeln('You Need',m,'RMB.');
end
else
begin
m:=3;
t:=l-3;
t:=t*1.6;
m:=m+t;
writeln('You Need',m,'RMB.');
end;
end
else
begin
writeln('Sorry Error Back!');
goto 1;
end;
readln;
end.
输入某学生成绩,根据成绩的好坏输出相应评语。如果成绩在90分以上,输出评语:优秀(outstanding)。如果成绩在60分到90分之间,输出评语:良好(satisfactory)。如果成绩不足60分,输出评语:不及格(unsatisfactory)。
label 1;
var
m : real;
begin
1:
write('Please Enter Your Marks');
readln(m);
if m>=0 then
begin
if m>90 then writeln('outstanding');
if (m>=60) and (m<=90) then writeln('satisfactory');
if m<60 then writeln('unsatisfactory');
end
else
begin
writeln('Are You fucking me? Check Your Marks and try again');
goto 1;
end;
readln;
end.
给一个不多于三位的正整数,求出它是几位数,并分别打印出各位上的数字。
label 1;
var
a,b,c : integer;
begin
1:
write('Enter Number');
readln(a);
if (a>=0) and (a<100) then
begin
b:=a div 10;
if b=0 then
begin
b:= a mod 10;
writeln('The Number has only 1 number and it''s ',b);
end
else
begin
c:=a mod 10;
writeln('The number has 2 number and they are ','shi wei is ',b,' ','and ge wei is ',c);
end;
end
else
begin
writeln('=w= Error,try it again');
goto 1;
end;
readln;
end.
输入三个数a,b,c,打印出最大者.
var
a,b,c : integer;
begin
readln(a,b,c);
if (a>b) then
begin
if (a>=c) then write(a);
if (c>=a) then write(c);
end;
if (b>a) then
begin
if (b>=c) then write(b);
if (c>=b) then write(c);
end;
if (a=b) then
begin
if (a>c) then write(a);
if (c>=a) then write(c);
end;
readln;
end.
Pascal:选择结构的程序设计,习题
https://Mundnaity.moe/post/pascal_chap3_ex