MATRIKS DALAM DEV CPP
#include <cstdlib>
#include <iostream>
using namespace std;
class Arr2
{
private : int i1,i2; //property
public : void Masuk()
{
cout<<"Jumlah Baris = ";
cin>>i1;
cout<<"Jumlah Kolom = ";
cin>>i2;
cout<<endl;
int matrik [i1][i2]; //deklarasi dan inisialisasi array
//mengisi array
for(int i = 0; i<i1; i++)
{
for(int j = 0; j<i2; j++)
{
cout<<"Nilai matrik ke ["<<i<<","<<j<<"] = ";
cin>>matrik [i][j];
}
}
cout<<endl;
//menampilkan isi matrik
for(int i = 0; i<i1; i++)
{
for(int j = 0; j<i2; j++)
{
cout<<"Isi matrik ke ["<<i<<","<<j<<"] adalah "<<matrik [i][j]<<endl;
}
}
}
};
int main(int argc, char *argv[])
{
Arr2 arre; //deklarasi Class Arr2
arre.Masuk(); //panggil Method Masuk dari Class Arr2
cout<<endl;
cout<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
__________________________________________________________________________________
#include <iostream>
using namespace std;
int inputt()
{
int x[2][2];
cout<< " Input matrik A
:" <<endl;
cout <<"_______________" <<endl;
for (int bar =0; bar <=1; bar++)
{
for (int kol =0;kol <=1; kol++)
{
cout<< "a
["<<(bar+1)<<","<<(kol+1)<<"]=";
cin>>x[bar][kol];
}
}
int y [2][2];
cout<< " Input matrik B
:" <<endl;
cout <<"_______________" <<endl;
for (int bar =0; bar <=1; bar++)
{
for (int kol =0;kol <=1;kol++)
{
cout<< "b
["<<(bar+1)<<","<<(kol+1)<<"]=";
cin>>y[bar][kol];
}
}
int z [2][2];
for ( int bar=0;bar<=1 ;bar++)
{
for (int kol =0;kol <=1;kol++)
{
z[bar][kol] = x[bar][kol]+y[bar][kol];
}
}
cout<<"Hasil penjumlahan
|A|+|B| = "<<endl;
cout<<"_________________________"<<endl;
for (int bar=0;bar <=1;bar++)
{
cout<<"|";
for (int kolA=0; kolA <=1; kolA++)
{
cout<<x [bar,kolA]
<<"";
}
cout<<"|";
cout<<"|";
for (int kolB=0;kolB <=1;kolB++)
{
cout<<y [bar,kolB ] <<
"";
}
cout<<"|";
cout<<"|";
for (int kolC=0;kolC<=1;kolC++)
{
cout<<z [bar,kolC ] <<
"";
}
cout<<"|"<<endl;
}
};
int main()
{
int matA[2][2];int matB[2][2];int matC[2][2];
inputt();
}
Tidak ada komentar:
Posting Komentar