Jumat, 24 Juni 2011

Program C++ menjumlahkan dua buah matriks

Haii .... My friends, this time we will learn about the two-dimensional array in which case fixed on the matrix. For this time I'll give a little lesson for us all that is adding two matrices. Okeeey ... friends now can see the algorithms and programs ... Lets get it ...! Hehehe

Algoritma :
Procedure matriks_jumlah (input matriks1, matriks2 : matriks ; baris, kolom : integer; output jumlah : matiks)
Deklarasi
i, j             : integer

Deskripsi
for i <= 1 to baris do
for j <= 1 to kolom do
jumlah[i,j] = matriks1[i,j] + matriks2[i,j]
endfor
endfor

Berikut kode programnya :

#include <iostream.h>

void baca_matriks(int mat[10][10], int baris, int kolom)
{  int i,j;
for (i=0; i<baris; i++)
for (j=0; j<kolom; j++)
{ cout<<"Data ["<<i+1<<","<<j+1<<"] :";
  cin>>mat[i][j];
}
}

void matriks_jumlah(const int matriks1[10][10], const int matriks2[10][10], int baris, int kolom, int jumlah[10][10])
{  int i,j;
for (i=0; i<baris; i++)
{ for (j=0; j<kolom; j++)
jumlah[i][j]=matriks1[i][j]+matriks2[i][j];}
void cetak_matriks(const int A[10][10], int baris, int kolom)
{  int i,j;
for (i=0; i<baris; i++)
{ for (j=0; j<kolom; j++)
cout<<A[i][j]
cout<<endl;
}
}
void main(){
int m,n;
int matriks1[10][10], matriks2[10][10];
int jumlah[10][10];
cout<<"Banyak baris : ";
cin>>m;
cout<<"Banyak kolom : ";
cin>>n;
cout<<"Data matriks ke-1\n";
baca_matriks(matriks1,m,n);
cetak_matriks(matriks1,m,n);
cout<<"Data matriks ke-2\n";
baca_matriks(matriks2,m,n);
cetak_matriks(matriks2,m,n);
matriks_jumlah(matriks1,matriks2,m,n,jumlah);
cout<<"Hasil penjumlahan : \n";
cetak_matriks(jumlah,m,n);
}


explanation:
In the above program is a program to add two matrices together with the terms of his order, m rows and n columns. To find out how two matrices can be added together, can be illustrated as follows: For example: A2x2 plus B2x2. The result is also an example 2x2 matrix matrix size C2x2.Penjumlahan done element by element in the appropriate place.

0 komentar:

Posting Komentar

Template by:

Free Blog Templates