PERKALIAN MATRIKS
#include <iostream>
//#include <conio>
#include <iomanip>
#include <cstdlib>
using namespace std;
int i, j, k,baris,kolom,m1[10]
[10], m2[10]
[10],hasil [10]
[10];
int main ()
{
//clrscr();
cout<<"operasi perkalian matrix\n";
do
{
cout<<"jumlah baris="; cin>>baris;
cout<<"jumlah kolom="; cin>>kolom;
}
while ((baris>10)||(kolom>10));
/* do
while (kolom>10); */
cout <<"\nMatrix A"<<endl;
for (i=0; i<baris; i++)
for (j=0; j<kolom; j++)
{
cout<<"data ["<<i<<","<<j<<"]=";
cin>>m1 [i][j];
}
cout<<"\nMatrix 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]=0;
}
for (k=0; k<3; k++)
hasil [i][j]=hasil [i][j]+m1 [i][j]+m2 [i][j];
cout<<"\nHasilnya......"<<endl;
cout<<"matrix A+ matrix B = matrix C";
for (i=0; i<baris; i++)
{
cout <<'\n';
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;
}
system ("PAUSE");
return 0;
//getch();
}
//#include <conio>
#include <iomanip>
#include <cstdlib>
using namespace std;
int i, j, k,baris,kolom,m1[10]
[10], m2[10]
[10],hasil [10]
[10];
int main ()
{
//clrscr();
cout<<"operasi perkalian matrix\n";
do
{
cout<<"jumlah baris="; cin>>baris;
cout<<"jumlah kolom="; cin>>kolom;
}
while ((baris>10)||(kolom>10));
/* do
while (kolom>10); */
cout <<"\nMatrix A"<<endl;
for (i=0; i<baris; i++)
for (j=0; j<kolom; j++)
{
cout<<"data ["<<i<<","<<j<<"]=";
cin>>m1 [i][j];
}
cout<<"\nMatrix 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]=0;
}
for (k=0; k<3; k++)
hasil [i][j]=hasil [i][j]+m1 [i][j]+m2 [i][j];
cout<<"\nHasilnya......"<<endl;
cout<<"matrix A+ matrix B = matrix C";
for (i=0; i<baris; i++)
{
cout <<'\n';
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;
}
system ("PAUSE");
return 0;
//getch();
}
Komentar
Posting Komentar