Advertisement
AshfaqFardin

Matrix Addition

Jul 30th, 2021
870
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int row = 3;
  8.     int column = 3;
  9.    
  10.     int matrix_A[3][3];
  11.     int matrix_B[3][3];
  12.    
  13.     //taking inputs
  14.     for(int i = 0; i < row; i++){
  15.         for(int j = 0; j < column; j++){
  16.             matrix_A[i][j] = i + j + 1;
  17.             matrix_B[i][j] = i + j + 2;
  18.         }
  19.     }
  20.     cout << "MATRIX A: \n";
  21.     for(int i = 0; i < row; i++){
  22.         for(int j = 0; j < column; j++){
  23.             cout << matrix_A[i][j] << " ";
  24.         }
  25.         cout << endl;
  26.     }
  27.    
  28.     cout << "MATRIX B: \n";
  29.     for(int i = 0; i < row; i++){
  30.         for(int j = 0; j < column; j++){
  31.             cout << matrix_B[i][j] << " ";
  32.         }
  33.         cout << endl;
  34.     }
  35.    
  36.     cout << "Sum of Two Matrix:\n";
  37.     int matrix_C[3][3];
  38.     for(int i = 0; i < row; i++){
  39.         for(int j = 0; j < column; j++){
  40.             matrix_C[i][j] = matrix_A[i][j] + matrix_B[i][j];
  41.             cout << matrix_C[i][j] << " ";
  42.         }
  43.         cout << endl;
  44.     }
  45.    
  46.     return 0;
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement