计算多种形状的面积

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.
posted @ 2010-01-01 18:14  SmartIOI  阅读(172)  评论(0)    收藏  举报
本站采用CC授权如需转载、引用文章,请务必附上作者及来源处。 Creative Commons License