program to add two matrices code example

Example: add two matrix

#include<iostream>
using namespace std;

int main() {
    int Matrix_A[3][3] = { { 2,3,4 },
                           { 5, 3, 4 },
                            { 4, 8, 9 }   };

    int Matrix_B[3][3] = { {3,4,5},
                         {7,8,9},
                          {2,3,4} };
    int Matrix_C[3][3];
    // for addition
 

            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                Matrix_C[i][j] =  Matrix_A[i][j] + Matrix_B[i][j];
                }
        }
           
            cout << " THis is the Adding of two Matrix " << endl;

            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    cout << Matrix_A[i][j] << " + " << Matrix_B[i][j] << " = " << Matrix_C[i][j] << endl;
                }
            }

// 


}

Tags:

Cpp Example