rizaarifudin[dot]com

Berbagi ilmu, pengalaman, tips dan trik, software

You are here: » Pascal: Latihan Procedure

Pascal: Latihan Procedure

Berikut ini merupakan latihan procedure untuk menukarkan nilai melalui paramater by reference dan parameter by value:

Program Tukar_Array;
Uses WinCrt;
Type
   Baris = Array [1..100] of integer;
Var
   A,B : Baris;
   i ,n: byte;


Procedure TukarVar(Var x,y :integer);
Var
   Temp:Integer;
Begin
     Temp :=x;
     x:=y;
     y:=Temp;
End;

Procedure TukarArr(Var A,B : Baris;N:byte);
Var
   j:byte;
Begin
   For j:= 1 to N do
        TukarVar(A[j],B[j]);
end;

Procedure Input(Var C: Baris;N:byte);
Begin
   for i := 1 to n do
     begin
          Write('Elemen [',i,'] : ');
          readln(C[i]);
     end;
end;

Procedure Tulis(A,B: Baris;N:byte);
Begin
     Writeln('Index':5,'ARRAY A':15,'ARRAY B':10);
     for i := 1 to n do
       Writeln(i:5,A[i]:10,B[i]:10);
     Writeln;
end;

Begin
     Writeln('PROGRAM TUKAR ISI ARRAY');
     Writeln('=======================');
     Write('Masukkan banyaknya index : ');
     readln(n);
     Writeln;
     Writeln('ARRAY A : ');
     Input(A,n);
     Writeln('ARRAY B : ');
     Input(B,n);
     clrscr;
     Writeln('Sebelum Ditukar Menjadi :');
     Tulis(A,B,N);
     readkey;
     Writeln('Setelah Ditukar Menjadi :');
     TukarArr(A,B,n);
     Tulis(A,B,N);
     Write('Press Any Key to Exit...');
     readkey;
     DoneWinCrt;
end.

Semoga Bermanfaat

Posted by 3 Responses
 

Free Email Newsletter

Stay Updates with this Blog. Get Free email newsletter updates..

And then confirm your email subcription

   

3 Comments to “Pascal: Latihan Procedure”

  1. riza says:

    Program Tukar_Array;
    Uses WinCrt;
    Type
    Baris = Array [1..10,1..10] of integer;
    Var
    A,B : Baris;
    i,j ,n,m: byte;

    Procedure TukarVar(Var x,y :integer);
    Var
    Temp:Integer;
    Begin
    Temp :=x;
    x:=y;
    y:=Temp;
    End;

    Procedure TukarArr(Var A,B : Baris; n,m:byte);
    Var
    i,j:byte;
    Begin
    for i := 1 to n do
    for j := 1 to m do
    TukarVar(A[i,j],B[i,j]);
    end;

    Procedure Input(Var C: Baris;n,m:byte);
    Begin
    for i := 1 to n do
    for j := 1 to m do
    begin
    Write(‘Elemen [‘,i,’,’,j,’] : ‘);
    readln(C[i,j]);
    end;
    end;

    Procedure Tulis(A,B: Baris;n,m:byte);
    Begin
    Writeln(‘Index’:5,’ARRAY A’:15,’ARRAY B’:10);
    for i := 1 to n do
    for j := 1 to m do
    Writeln(i:2,j:2,A[i,j]:5,B[i,j]:5);
    Writeln;
    end;
    Procedure Tulis2(C: Baris;n,m:byte);
    Begin
    for i := 1 to n do
    begin
    for j := 1 to m do
    Write(C[i,j]:5);
    Writeln;
    end;
    end;
    Begin
    Writeln(‘PROGRAM TUKAR ISI MATRIKS’);
    Writeln(‘=======================’);
    Write(‘Masukkan ordonya : ‘);
    readln(n,m);
    Writeln;
    Writeln(‘ARRAY A : ‘);
    Input(A,n,m);
    Writeln(‘ARRAY B : ‘);
    Input(B,n,m);
    clrscr;

    Writeln(‘Sebelum Ditukar Menjadi :’);
    Writeln(‘Matriks A:’);
    Tulis2(A,n,m);
    Writeln(‘Matriks B:’);
    Tulis2(B,n,m);
    readkey;

    Writeln(‘Setelah Ditukar Menjadi :’);
    TukarArr(A,B,n,m);
    Writeln(‘Matriks A:’);
    Tulis2(A,n,m);
    Writeln(‘Matriks B:’);
    Tulis2(B,n,m);
    Write(‘Press Any Key to Exit…’);
    readkey;
    DoneWinCrt;
    end.

  2. operator says:

    TUGAS TAMBAHAN:

    “Membuat Program Perkalian Matriks dengan menggunakan Procedure”

    Catatan: Minggu depan ditampilkan.

  3. darto demak says:

    pertama. Good
    Keduanya. Good Good
    Ketiganya. Good Good Good

Leave your comment here:

*

Nov
29
2011
 
Archives
Chat
Name:
Email:
For:  
Mail will not be published
(but it's required)