计算多种形状的面积
program CalculateAreaCircumference;
var
a, b, c, h, r, p : real;
shape : char;
begin
writeln('Calculate Area & Circumference of a shape.');
write('Please select what shape will you calculate (C: circle; T: triangle; S: square; R: rectangle): ');
readln(shape);
case shape of
'c', 'C': begin
write('Please input the radiiradius: ');
readln(r);
writeln('Area is ', pi*r*r:8:2, ', Circumference is ', 2*pi*r:8:2);
end;
't', 'T': begin
write('Please input the side lengths: ');
readln(a, b, c);
if (a+b > c) and (b+c > a) and (a+c > b) then begin
p := (a+b+c)/2;
writeln('Area is ', sqrt(p*(p-a)*(p-b)*(p-c)):8:2, ', Circumference is ', a+b+c:8:2);
end;
end;
's', 'S': begin
write('Please input the side length: ');
readln(a);
writeln('Area is ', a*a:8:2, ', Circumference is ', 4*a:8:2);
end;
'r', 'R': begin
write('Please input the length & wideth: ');
readln(a, b);
writeln('Area is ', a*b:8:2, ', Circumference is ', 2*(a+b):8:2);
end;
else
writeln(' input error. :( ...');
end;
end.
================ OR ==========================
program nvilk;
var
a, b, c, d : real;
shape : string;
begin
read(shape);
if upcase(shape) = 'CIRCLE' then begin
write('please input a number: ');
read(a);
writeln(a*a*pi:0:2);
end
else
if upcase(shape) = 'TRIANGLE' then begin
write('please input three numbers: ');
read(a, b, c);
d := (a+b+c)/2;
writeln(sqrt(d*(d-a)*(d-b)*(d-c)):0:2);
end
else begin
write('please input two numbers: ');
read(a, b);
writeln(a*b:0:2);
end;
end.
var
a, b, c, h, r, p : real;
shape : char;
begin
writeln('Calculate Area & Circumference of a shape.');
write('Please select what shape will you calculate (C: circle; T: triangle; S: square; R: rectangle): ');
readln(shape);
case shape of
'c', 'C': begin
write('Please input the radiiradius: ');
readln(r);
writeln('Area is ', pi*r*r:8:2, ', Circumference is ', 2*pi*r:8:2);
end;
't', 'T': begin
write('Please input the side lengths: ');
readln(a, b, c);
if (a+b > c) and (b+c > a) and (a+c > b) then begin
p := (a+b+c)/2;
writeln('Area is ', sqrt(p*(p-a)*(p-b)*(p-c)):8:2, ', Circumference is ', a+b+c:8:2);
end;
end;
's', 'S': begin
write('Please input the side length: ');
readln(a);
writeln('Area is ', a*a:8:2, ', Circumference is ', 4*a:8:2);
end;
'r', 'R': begin
write('Please input the length & wideth: ');
readln(a, b);
writeln('Area is ', a*b:8:2, ', Circumference is ', 2*(a+b):8:2);
end;
else
writeln(' input error. :( ...');
end;
end.
================ OR ==========================
program nvilk;
var
a, b, c, d : real;
shape : string;
begin
read(shape);
if upcase(shape) = 'CIRCLE' then begin
write('please input a number: ');
read(a);
writeln(a*a*pi:0:2);
end
else
if upcase(shape) = 'TRIANGLE' then begin
write('please input three numbers: ');
read(a, b, c);
d := (a+b+c)/2;
writeln(sqrt(d*(d-a)*(d-b)*(d-c)):0:2);
end
else begin
write('please input two numbers: ');
read(a, b);
writeln(a*b:0:2);
end;
end.


浙公网安备 33010602011771号