Perkalian MatriksSearching Data

Algoritma

Judul : Algoritma menghitung perkalian matrix
Spesifikasi : {menampilkan hasil perkalian matrix }
Deklarasi (kamus) :

Deklarasi (kamus)  :

M,n,hasil     : Array of Integer

i,j    : Integer

Deskripsi    :

m[][] ?{{7, 2}, {3, 5}}

n[][]?{{8, 1}, {3, 6}}

Write(“matriks m :”);

for i=0 to m.length do

for j=0  to m[i].length do

Write(m[i][j] ,” “)

endfor

Write(“matriks n :”)

for  i=0 to i<n.length do

for j=0 to j<n[i].length do

Write(n[i][j] ,” “)

endfor

for i = 0to hasil.length do

for j=0 to j<hasil.length do

hasil[i][j]=0;

for k=0 to k<hasil.length do

hasil[i][j]+=m[i][k]*n[k][j]

endfor

endfor

endfor

for i = 0 to i < hasil.length do

for j=0 to j<hasil.length do

Write(hasil[i][j],” “)

Endfor

endfor

Program :


import java.util.*;

class Mariks {

public static void main (String [] args){

int m[][]={{7, 2}, {3, 5}};

int n[][]={{8, 1}, {3, 6}};

//menampilkan matriks m :

System.out.println("matriks m :");

for (int i=0; i<m.length; i++)

{

for(int j=0; j<m[i].length; j++)

{

System.out.print(m[i][j] +" ");

}

System.out.println();

}

//menampilkan matriks n :

System.out.println("matriks n :");

for (int i=0; i<n.length; i++)

{

for(int j=0; j<n[i].length; j++)

{

System.out.print(n[i][j] +" ");

}

System.out.println();

}

//hasil [m*n] :

System.out.println("Perkalian mxn :");

int[][]hasil=new int[2][2];

for (int i = 0; i < hasil.length; i++) {

for(int j=0;j<hasil.length;j++){

hasil[i][j]=0;

for(int k=0;k<hasil.length;k++){

hasil[i][j]+=m[i][k]*n[k][j];

}

}

}

//menampilkan matrix

for (int i = 0; i < hasil.length; i++) {

for(int j=0;j<hasil.length;j++){

System.out.print(hasil[i][j]+" ");

}

System.out.println();

}

}

}

About Ade Akbar

Hidup, Berarti dan Mati

Posted on November 30, 2011, in Tugas. Bookmark the permalink. Tinggalkan komentar.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: