C++ Program to add the matrices is given below. Here we will first define the size of the input matrices and then will add the both matrices using 'add' method and will store their result in the third matrix

C++ Program to add two matrices:

#include <bits/stdc++.h>
using namespace std;

#define n 3
void add(int a[][n], int b[][n], int c[][n]) {
    for (int i = 0; i < n ; i++) {
        for(int j=0; j< n; j++) {
            c[i][j] = a[i][j] + b[i][j];
        }
    }
}

int main() {

    int a[n][n],b[n][n], c[n][n];

    //taking the inpur ot matrix a 
    cout<<"\n Enter the matrice a input:\n";

    for (int i = 0; i < n ; i++) {
        for(int j=0; j< n; j++) {
            cin>>a[i][j];
        }
    }

    //taking the inpur ot matrix a 
    cout<<"\n Enter the matrice b input:\n";

    for (int i = 0; i < n ; i++) {
        for(int j=0; j< n; j++) {
            cin>>b[i][j];
        }
    }

    add(a, b, c);

    //printing the sum matrice i.e output of the addition
    cout<<"\n\n Sum of the matrice a and matrice b is: \n";
    for (int i = 0; i < n ; i++) {
        for(int j=0; j< n; j++) {
            cout<<c[i][j]<< " ";
        }
        cout<<"\n";
    }
}



OUTPUT:
addition of matrices c++