Sunday, May 1, 2011

mencari posisi terakhir dalam pascal

program memanggil_fungsi;
uses wincrt;
type
    tabint=array [1..100] of integer;


function searching (A:tabint; n,x:integer):boolean;
var
   i:integer;
   found,hasil: boolean;

begin
     i:=1;
     found:=false;
     while (not found) and (i<=n) do
           if A[i] = x then
              found:= true
           else
               i:=i+1;

end;



function sama (A,B : tabint; n,m: integer):boolean;
var
   found:boolean;
   i:integer;
begin
     if m=n then
       begin
        i:=1;
        found:=true;
        while found and (i<=n) do
          begin
              if A[i] <> B[i] then
                 found := false
              else
                 i:=i+1;
         end;
       end
               
     else
        found:=false;

    
end;

{***PROGRAM UTAMA***}

var
   A,B:tabint ;
   i,n,m,x : integer;
   found : boolean;
begin
     write('masukkan batas 1: ');
     readln(n);

     write('masukkan batas 2: ');
     readln(m);

     writeln ('tabel pertama : ');
     for i:=1 to n do
         readln (A[i]);

     writeln('tabel kedua : ');
     for i:=1 to m do
         readln(B[i]);

     write ('bilangan yang dicari : ');
     readln(x);

     searching(A,n,x);
     writeln(found);

     sama(A,B,n,m);
     writeln (found);

end.

No comments:

Post a Comment