Add two matrix

#include <iostream>
using namespace std;
#define N 4

void add(int A[][N], int B[][N], int C[][N]){
    int i,j;
    for(i = 0; i < N; i++){
        for(j = 0; j < N; j++){
            C[i][j] = A[i][j] + B[i][j];
        }
    }
}

int main(){
    int arr1[N][N] = {{1,1,1,1},
                      {2,2,2,2},
                      {3,3,3,3}};
    int arr2[N][N] = {{3,3,3,3},
                      {2,2,2,2},
                      {1,1,1,1}};
    
    int arr3[N][N],i,j;
    add(arr1,arr2,arr3);
    cout<<"print add Array"<<endl;
    for(i = 0; i < N; i++){
        for(j = 0; j < N; j++)
        {
            cout<<arr3[i][j]<<" ";
            
        }
        cout<<endl;
    }
    return 0;
}

    Leave a Reply

    Your email address will not be published.

    Need Help?