Thursday, 20 June 2013

Mencari Rata-Rata, Persamaan Kuadrat dan Luas Segitiga Menggunakan Turbo Pascal

program ellinjuniarti;

uses wincrt;

var
   pilih:byte;

procedure rata_rata;  {awal prosedur rata-rata}

var
   i,n : integer;
   x,sum,mean : real;
   ulang : char;

begin
   repeat
   clrscr ;
   gotoxy (13,2) ; writeln('===========================================');
   gotoxy (13,3) ; writeln('=            MENCARI RATA-RATA            =');
   gotoxy (13,4) ; writeln('===========================================');

   writeln;
   write('banyaknya data = '); read(n);
   sum:=0;

   for i:=1 to n do

     begin
     write('data ke-',i,'='); read(x);
     sum:=sum+x;
     end;

     mean:=sum/n;
     writeln;
     writeln('Jadi, rata_rata = ',mean:0:2);

     repeat
     writeln;
     write('Mau coba lagi? (Y/N): '); readln(ulang);

     until  (ulang='Y') or (ulang='y') or (ulang='N') or (ulang='n')  ;
     until (ulang = 'N') or (ulang='n');

end; {akhir prosedur rata-rata}


procedure pk; {awal prosedur PK}

var
   a,b,c,D,x1,x2 : real;
   ulang : char;
 

begin
   repeat
   clrscr ;
   gotoxy (13,2); writeln('     ===========================================');
   gotoxy (13,3); writeln('     =   Mencari Akar-Akar Persamaan Kuadrat   =');
   gotoxy (13,3); writeln('     =      Bentuk Umum ax^2 + bx + c = 0      =');
   gotoxy (13,4); writeln('     ===========================================');

   gotoxy (13,6); write ('Masukkan nilai a: ');read(a);
   gotoxy (13,7); write ('Masukkan nilai b : ');read(b);
   gotoxy (13,8); write ('Masukkan nilai c : ');read(c);

   D:=(b * b) - 4 * a * c;
   gotoxy (13,10); writeln('Nilai D= ',D:0:2);
   writeln;

        if D=0 then
           begin
             x1:=-b/2*a;
             x2:=x1;
             gotoxy (13,12); writeln('Karena D = 0, maka "PK mempunyai dua akar real yang sama" ');
           gotoxy (13,13); writeln('Nilai x1=x2= ',x1);
           end;

        if D >0 then
           begin
             x1:=(-b+sqrt(D))/(2*a);
             x2:=(-b-sqrt(D))/(2*a);
               gotoxy (13,12);writeln('Karena D > 0, maka "PK mempunyai dua akar real yang berbeda" ');
             gotoxy (13,13); writeln('Nilai x1= ',x1);
             gotoxy (13,14); writeln('Nilai x2= ',x2);
           end;

        if D<0 then
           begin
             gotoxy (13,12);writeln('Akar-akar persamaan kuadrat adalah imajiner');
           end;

     repeat
     writeln;
     write('Mau coba lagi? (Y/N): '); readln(ulang);

     until  (ulang='Y') or (ulang='y') or (ulang='N') or (ulang='n')  ;
     until (ulang = 'N') or (ulang='n');

end; {akhir prosedur PK}


procedure luas_segitiga;  {awal prosedur luas segitiga}

var
   a,t,luas : real;
   ulang : char;

begin
   repeat
   clrscr ;
   gotoxy (13,2); write ('===========================================');
   gotoxy (13,3); write ('=          MENCARI LUAS SEGITIGA          =');
   gotoxy (13,4); write ('===========================================');
   gotoxy (13,6); write ('masukkan nilai a= '); read (a);
   gotoxy (13,7); write ('masukkan nilai t= '); read (t);

   luas:=(a*t)/2;

   gotoxy (13,9); writeln ('Jadi, luas segitiga adalah = ',luas:0:2);

   repeat
   writeln;
   write ('Mau coba lagi? (Y/N): ');readln (ulang);
   until (ulang='Y') or (ulang='y') or (ulang='N') or (ulang='n');
   until (ulang='N') or (ulang='n');
  
end; {akhir prosedur luas segitiga}


{Program Utama}

begin
clrscr;
repeat
    clrscr;
     gotoxy (16,2);write(' =======================');
     gotoxy (16,3);write(' =        M E N U      = ');
     gotoxy (16,4);write(' =======================');
     gotoxy (13,6);write('(1) Rata-Rata');
     gotoxy (13,7);write('(2) PK');
     gotoxy (13,8);write('(3) Luas Segitiga');
     gotoxy (13,9); write ('(4) Exit');
     gotoxy (14,11);write ('Pilih [1..4]');
     gotoxy (12,12);write('Masukkan pilihan = ');readln(pilih);

if pilih=1 then rata_rata
else
if pilih=2 then pk
else
if pilih=3 then luas_segitiga ;
until pilih=4 ;

clrscr;
    
     writeln;
     writeln;
     writeln('               Terima Kasih Sudah Memakai Program Ini       ');
     writeln('                         Sampai Jumpa Lagi                  ');
     writeln('                                ^_^                         ');
     writeln;
     writeln;
     writeln('                 # # # #   ,                   ***   ***    ');  
     writeln('                #;;;;;;;#     ,     ,        *     *     *  ');
     writeln('               #;;;;;;;;;#        ,         *             * ');
     writeln('              #;;;;;;;;;;;#                 *             * ');
     writeln('              _____________     ,            *           *  ');
     writeln('                    |                          *       *    ');
     writeln('                    |(@_@)      v v v            *   *      ');
     writeln('                    () ()        v v               *        ');
     writeln('                    (_)(_)))      v                         ');
     writeln('              ___v________________v__                       ');



     gotoxy (13,20); write ('==============================');
     gotoxy (13,21); write ('= created by: Ellin Juniarti =');
     gotoxy (13,22); write ('=         06121408012        =');
     gotoxy (13,23); write ('==============================');


end.

No comments:

Post a Comment