Bahasa Pemrograman (Matriks)


ALGORITMA PERKALIAN

1. Mulai.

2. Matrik A.

3. Masukkan jumlah baris dan kolom Matrik A misal (n x m).

4. Masukkan data Matrik A.

5. Keluar data Matrik A.

6. Matrik B.

7. Masukkan jumlah kolom Matrik B saja karena jumlah baris Matrik B sama dengan jumlah kolom Matrik A. Jadi dapat dimisalkan dengan (m x p).

8. Masukkan data Matrik B.

9. Keluar data Matrik B.

10. Perkalian Matrik A dengan Matrik B.

11. for (i=0;i<n;i++)

12. for (j=0;j<p;j++)

13. kali[i][j]=0;

14. for (k=0;k<m;k++)

15. kali[i][j]=kali[i][j] + (nilai[i][k]*nilai2[k][j]);

16. next k.

17. next j.

18. next i.

19. Keluar Matrik A x Matrik B.

20. Selesai.

PENJUMLAHAN DAN PENGURANGAN (JAVA)

class matrik

{

public static void main (String[] args)

{

System.out.println (“Nama     : Agus Wibowo”);

System.out.println (“No. BP   : 07173042”);

System.out.println (“Kelompok : 3”);

System.out.println (“Asisten  : Dian Primasari”);

System.out.println (”           Dona Osman”);

System.out.println (“”);

int z,n,m,o,p;

System.out.println (“Passwordnya 123”);

z=Keyin.inInt (“Masukkan Password!!!”);

System.out.println (“”);

if (z==123)

{

System.out.println (“Matrik A”);

System.out.println (“~~~~~~~~”);

n=Keyin.inInt (“Jumlah Baris =”);

m=Keyin.inInt (“Jumlah Kolom =”);

System.out.println (“”);

int nilai[][]=new int[n][m];

System.out.println (“Inputkan Data!!”);

int i,j;

for (i=0;i<n;i++)

for (j=0;j<m;j++)

{

nilai[i][j]=Keyin.inInt (“Masukkan Nilai “+(i+1)+(j+1)+”=”);

}

for (i=0;i<n;i++)

{

for (j=0;j<m;j++)

{

System.out.print (nilai[i][j]+” | “);

}

System.out.println ();

System.out.println ();

}

////////////////////////////////////////////////////////////////////////////////

System.out.println (“Matrik B”);

System.out.println (“~~~~~~~~”);

o=Keyin.inInt (“Jumlah Baris =”);

if (o==n)

{

p=Keyin.inInt (“Jumlah Kolom =”);

System.out.println (“”);

if (p==m)

{

int nilai2[][]=new int[o][p];

System.out.println (“Inputkan Data!!”);

for (i=0;i<o;i++)

for (j=0;j<p;j++)

{

nilai2[i][j]=Keyin.inInt (“Masukkan Nilai “+(i+1)+(j+1)+”=”);

}

for (i=0;i<o;i++)

{

for (j=0;j<p;j++)

{

System.out.print (nilai2[i][j]+” “);

}

System.out.println ();

System.out.println ();

}

////////////////////////////////////////////////////////////////////////////////

System.out.println(“”);

System.out.println(“Matrik A + Matrik B”);

System.out.println(“~~~~~~~~~~~~~~~~~~~”);

int tambah[][]=new int[n][m];

for (i=0;i<n;i++)

{

for (j=0;j<m;j++)

{

tambah[i][j]=nilai[i][j]+nilai2[i][j];

System.out.print(tambah[i][j]+” “);

}

System.out.println ();

System.out.println ();

}

////////////////////////////////////////////////////////////////////////////////

System.out.println(“”);

System.out.println(“Matrik A – Matrik B”);

System.out.println(“~~~~~~~~~~~~~~~~~~~”);

int kurang[][]=new int[n][m];

for (i=0;i<n;i++)

{

for (j=0;j<m;j++)

{

kurang[i][j]=nilai[i][j]-nilai2[i][j];

System.out.print(kurang[i][j]+” “);

}

System.out.println ();

System.out.println ();

}

}

else

System.out.println(“Dalam Penjumlahan Atau Pengurangan Matrik, Kolomnya harus sama!!!”);

}

else

System.out.println(“Dalam Penjumlahan Atau Pengurangan Matrik, Barisnya harus sama!!!”);

}

else

System.out.println(“Error”);

}

}

PERKALIAN(C++)

#include<iostream.h>

void main()

{

int n,m,p,i,j,k,nilai[100][100],nilai2[100][100],kali[100][100];

cout<<“Matrik A\n”;

cout<<“Jumlah Baris = “;

cin>>n;

cout<<“Jumlah kolom = “;

cin>>m;

cout<<“Inputkan Data !!\n”;

for(i=0;i<n;i++)

for(j=0;j<m;j++)

{

cout<<“Masukkan Nilai “<<(i+1)<<(j+1)<<” = “;

cin>>nilai[i][j];

}

cout<<endl;

cout<<“Matrik A\n”;

cout<<endl;

for (i=0;i<n;i++)

{

for (j=0;j<m;j++)

{

cout<<nilai[i][j]<<” “;

}

cout<<endl;

cout<<endl;

}

/////////////////////////////////

cout<<“Matrik B\n”;

cout<<“Jumlah Baris =”<<m<<endl;

cout<<“Jumlah kolom =”;

cin>>p;

cout<<“Inputkan Data !!\n”;

for(i=0;i<m;i++)

for(j=0;j<p;j++)

{

cout<<“Masukkan Nilai “<<(i+1)<<(j+1)<<“=”;

cin>>nilai2[i][j];

}

cout<<endl;

cout<<“Matrik B\n”;

cout<<endl;

for (i=0;i<m;i++)

{

for (j=0;j<p;j++)

{

cout<<nilai2[i][j]<<” “;

}

cout<<endl;

cout<<endl;

}

//////////////////////////////////////////////////

for (i=0;i<n;i++)

{

for (j=0;j<p;j++)

{

kali[i][j]=0;

for (k=0;k<m;k++)

{

kali[i][j]=kali[i][j] + (nilai[i][k]*nilai2[k][j]);

}

}

}

cout<<endl;

cout<<“Matrik A X Matrik B\n”;

cout<<endl;

for (i=0;i<n;i++)

{

for (j=0;j<p;j++)

{

cout<<kali[i][j]<<” “;

}

cout<<endl;

cout<<endl;

}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s