Blog Kumpulan Tugas

Jumat, 17 Juni 2016

Penjumlahan 2 Matriks

#include <iostream>

using namespace std;

main(){
int a[2][2];
int b[2][2];
int hasil[2][2];
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<"Masukkan nilai matrik 1 ["<<i<<"]["<<j<<"] : "; cin>>a[i][j];
}
}

for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<"Masukkan nilai matrik 2 ["<<i<<"]["<<j<<"] : "; cin>>b[i][j];
}
}

for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<" "<<a[i][j]<<" ";
}
cout<<endl;
}

cout<<endl<<endl;

for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<" "<<b[i][j]<<" ";
}
cout<<endl;
}

for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
hasil[i][j] = a[i][j] + b[i][j];
}
}

cout<<endl<<"Hasil penjumlahan dua matriks diatas adalah : "<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<" "<<hasil[i][j]<<" ";
}
cout<<endl;
}


Share:

0 komentar:

Posting Komentar

Diberdayakan oleh Blogger.

Blog Archive