Viết chương trình tính diện tích hình chữ nhật, tam giác, hình bình hành, hình thang trong pascal giúp em với, mai kiểm tra rồi ạ

By Delilah

Viết chương trình tính diện tích hình chữ nhật, tam giác, hình bình hành, hình thang trong pascal
giúp em với, mai kiểm tra rồi ạ

0 bình luận về “Viết chương trình tính diện tích hình chữ nhật, tam giác, hình bình hành, hình thang trong pascal giúp em với, mai kiểm tra rồi ạ”

  1. * Tính diện tích hình chữ nhật

    program dthcn;

    var 

    a, b, c : integer;

    begin

    Write (‘Nhap chieu dai:’); read (a);

    Write (‘Nhap chieu rong:’); read (b);

    s := a * b;

    Write (‘Dien tich hinh chu nhat la:’,s);

    Readln

    End.

    * Tính diện tích hình thang

    program dtht;

    var

    a, b, h:Integer;

    s:real;

    begin

    Write(‘Nhap day lon:’);readln(a);

    Write(‘Nhap day nho:’);readln(b);

    Write(‘Nhap chieu cao:’);readln(h);

    s:=((a+b)*h)/2;

    WriteLn (‘Dien tich hinh thang la:’,s);

    readln

    end.

    * Tính diện tích tam giác

    program dttg;

    var

    a, h : integer;

    s : real;

    begin

    Write (‘Nhap chieu cao:’); read (h);

    Write (‘Nhap day:’); read (a);

    s := 1/2 * a * h;

    Write (‘Dien tich tam giac la:’,s);

    Readln

    End.

    * Tính diện tích hình bình hành

    program dthbh;

    var

    a, h : integer;

    s : real;

    begin

    Write (‘Nhap chieu cao:’); read (h);

    Write (‘Nhap day:’); read (a);

    s := a * h;

    Write (‘Dien tich hinh binh hanh la:’,s);

    Readln

    End.

    * Tính diện tích hình tròn

    program dthtr;

    const 

    pi=3.14;

    var

    r:Real;

    s:Real;

    begin

    Write(‘Nhap ban kinh:’); readln(r);

    s:=r*r*pi;

    write(‘Dien tich hinh tron:’,s);

    readln

    end.

    ———————–

    @vietdorapan

    Trả lời
  2. Program TINH_DIEN_TICH;
    Uses crt;
    Procedure HV;
      Var s,a:real;
      Begin
          Writeln(‘TINH DIEN TICH HINH VUONG:’);
          Write(‘Nhap chieu dai cua canh a = ‘);readln(a);
          s:=a*a;
         Writeln(‘Dien tich hinh vuong = ‘,s:6:2);
      End;
    Procedure HT;
    Var s,r:real;
    Begin
         Writeln(‘TINH DIEN TICH HINH TRON:’);
         Write(‘Nhap ban kinh R = ‘);readln(r);
         s:=pi*r*r;
         Writeln(‘Dien tich hinh tron = ‘,s:6:2);
    End;
    Procedure TG;
    Var a, b, c,s,p:real;
     Begin
        Writeln(‘TINH DIEN TICH TAM GIAC:’);
        Write(‘nhap a =’);readln(a);
        Write (‘nhap b =’);readln(b);
        Write(‘nhap c =’);readln(c);
        If ((a+b)>c)and((b+c)>a)and((a+c)>b) then
        Begin
             p:=(a+b+c)/2;
             s:=sqrt(p*(p-a)*(p-b)*(p-c));
             Writeln(‘Chu vi tam giac:’,2*p:4:2) ;
             Writeln(‘Dien tich tam giac:’,s:4:2);
         End
         Else
              Writeln(a,’, ‘,’, ‘,c,’ khong phai la ba canh cua tam giac’) ;
    End;
    Procedure CN;
    Var a, b, s:real;
    Begin
         Writeln(‘TINH DIEN TICH HINH CHU NHAT:’);
         Write(‘Nhap chieu dai a =’);readln(a);
         Write(‘Nhap chieu rong b= ‘);readln(b);
         s:= a*b;
         Writeln(‘Dien tich hinh chu nhat, s= ‘,s:6:2);
    End;
    Procedure menu;
    Var d:integer;
    Begin
         Clrscr;
         Writeln(‘CHON MOT TRONG CAC PHUONG AN SAU:’);
         Writeln(‘———————————-‘);
         Writeln(‘0: Quay ve man hinh soan thao’);
         Writeln(‘1: Tinh dien tich hinh vuong’);
          Writeln(‘2: Tinh dien tich hinh tron’);
         Writeln(‘3: tinh dien tich tam giac’);
         Writeln(‘4: Tinh dien tich hinh chu nhat’);
         Writeln(‘====================’);
        Write(‘ Hay chon mot phuong an: ‘); readln(d);
        Writeln(‘====================’);
        Writeln;
       Case d of
           0: Exit;
           1: HV;
           2: HT;
           3: TG;
           4: CN;
        End;
    End;
    Begin
         menu;
        Readln;
    End.

    Trả lời

Viết một bình luận