Program C++ Menentukan Matriks


#include <cstdlib>
#include <iostream>
#include <iomanip.h>

using namespace std;

int i, j, k, baris, kolom, m1[10][10], m2[10][10], hasil[10][10];

int main(int argc, char *argv[])
{
cout<<"Operasi Pengurangan dan Penjumlahan Matriks\n\n";
do
{
cout<<"Jumlah Baris : "; cin>>baris;
cout<<"Jumlah Kolom : "; cin>>kolom;

}
while ((baris>10)||(kolom>10));
/* do
while(kolom>10);
*/
cout<<"\nMatriks A "<<endl;
for(i=0;i<baris;i++)
for(j=0;j<kolom;j++){
cout<<"data["<<i<<", "<<j<<"] = ";
cin>>m1[i][j];
}
cout<<"\nMatriks B "<<endl;
for(i=0;i<baris;i++)
for(j=0;j<kolom;j++){
cout<<"data["<<i<<", "<<j<<"] = ";
cin>>m2[i][j];
}
for(i=0;i<baris;i++)
for(j=0;j<kolom;j++){
hasil[i][j]=m1[i][j] + m2[i][j];
}
for(k=0;k<3;k++)
hasil[i][j] = hasil[i][j] + m1[i][j] * m2[i][j];
cout<<"\nHasilnya... "<<endl;
cout<<"Matriks A + Matriks B = Matriks C\n";
for(i=0;i<baris;i++){
for(j=0;j<kolom;j++)
cout<<setw(4)<<m1[i][j];
cout<<"     ";
for(j=0;j<kolom;j++)
cout<<setw(4)<<m2[i][j];
cout<<"     ";
for(j=0;j<kolom;j++)
cout<<setw(4)<<hasil[i][j];
cout<<endl;
}
for(i=0;i<baris;i++)
for(j=0;j<kolom;j++){
hasil[i][j]=m1[i][j] - m2[i][j];
}
for(k=0;k<3;k++)
hasil[i][j] = hasil[i][j] - m1[i][j] - m2[i][j];
cout<<"\nHasilnya... "<<endl;
cout<<"Matriks A - Matriks B = Matriks C\n";
for(i=0;i<baris;i++){
for(j=0;j<kolom;j++)
cout<<setw(4)<<m1[i][j];
cout<<"     ";
for(j=0;j<kolom;j++)
cout<<setw(4)<<m2[i][j];
cout<<"     ";
for(j=0;j<kolom;j++)
cout<<setw(4)<<hasil[i][j];
cout<<endl;
}

cout<<endl<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}

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