Addition of 2 matrix in c++

This is the code for addition of 2 matrix in ordo 3x3. To do that, we use for looping rows and columns of the matrix. Lets see the example below :
#include <iostream.h>
#include <conio.h>

int main(){
typedef int matrik33[3][3];
matrik33 A,B,C;
int j,k;

// array A element
cout<<"Tugas no 1 & 4 (soalnya sama)"<<endl;
cout<<"Addition of Two Array 3x3"<<endl;
for(j=0;j<3;j++) {
   for(k=0;k<3;k++) {
   cout<<"A["<<j<<"]["<<k<<"] = ";
   cin>>A[j][k];
  }
 }
 cout<<endl<<endl;


 
 //mengisi elemen array B
for(j=0;j<3;j++) {
  for(k=0;k<3;k++) {
   cout<<"B["<<j<<"]["<<k<<"] = ";
   cin>>B[j][k];
  }
 }
 cout<<endl<<endl;


 
 //Process of array A + B
for(j=0;j<3;j++) {
  for(k=0;k<3;k++){
   C[j][k]=A[j][k] + B[j][k];
  }
 }



 //Show the result
cout<<"The Result is :"<<endl;
for(j=0;j<3;j++) {
  for(k=0;k<3;k++) {
   cout << "C[" << j << "]["<< k << "]= " << C[j][k]<< endl;
  }
 }
 getch();
 
}

Previous
Next Post »