Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include <iostream>

using namespace std;


int hasil[2][10][10];
int panjang[2][2];
int row = 0;
int col = 0;

void isiData (int jumlahMatriks) {


cout <<"Ordo Matrix"<<jumlahMatriks+1<<endl;
scanf("%d",&row);
cout<<"x"<<endl;
scanf ("%d", &col);
int matriks [row][col];

panjang[jumlahMatriks][0]= row;
panjang[jumlahMatriks][1]= col;

cout<<endl;

for(int x=0; x<row; x++){


for(int y=0;y<col;y++){
cout<<"Index("<<x+1<<","<<y+1<<"):";
scanf("%d", &matriks[x][y]);
hasil[jumlahMatriks][x][y]=matriks[x][y];
}
}
cout << endl;
}
void tampilData (int jumlahMatriks) {
for(int x=0; x<panjang[jumlahMatriks][0];x++){
cout<<"";
for(int y=0;y<panjang[jumlahMatriks][1];y++){
cout<<hasil[jumlahMatriks][x][y]<<" ";
}
cout<<""<<endl;
}
cout<<endl;
}
void penjumlahan(){
bool a= panjang[0][0]== panjang[1][0];
bool b= panjang[0][1]== panjang[1][1];

if (a&&b) {
for(int x=0;x<panjang[0][0];x++){
cout<<"";
for(int y=0;y<panjang[0][1];y++){
cout<<hasil[0][x][y]+hasil[1][x][y]<<" ";
}
cout<<""<<endl;
}
}
}
int main()
{
cout<<"Nama : Putri Nurrifkadillah"<<endl;
cout<<"NIM : K1B020002"<<endl;
cout<<"======================================"<<endl;
cout<<"Penjumlahan Matriks "<<endl;
cout<<"======================================"<<endl;
int input = 2;
do{
cout<<"1. Isi data"<<endl;
cout<<"2. Penjumlahan"<<endl;
cout<<"Pilihan:";

scanf("%d", &input);
if(input==1){
for(int i=0;i<2;i++){
isiData(i);
}
}else if (input==2){
for(int i=0;i<2;i++){
tampilData(i);
if(i==0){
cout<<"+"<<endl;
}else{
cout<<"="<<endl;
}
}
penjumlahan();
}else{
cout<<"Pilihan tidak tersedia"<<endl<<endl;
}

}while(input !=2);
return 0;
}

You might also like