Below did not work. Is there anyother way?

#include<stdio.h>
#include<math.h>

const int No=2;

int* mat_sum(int[][No], int[][No],int);

void main(){


int A[No][No]={{0,2},{0,1}};
int B[No][No]={{0,1},{1,0}};
int *Result=0;

Result=mat_sum(A,B,No);

}


int* mat_sum (int A[][No], int B[][No],int length){
int *C=new int[No][No];


for (int i=0;i<length;i++){
for (int j=0;j<length;j++){
C[j]=0;
C[j]=A[j]+B[j];
// printf("%2d",C[j]);
}

}
return C;

}

You could pass the result matrix as a parameter to your function.

const int No = 2;

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

int main()
{
   int A[No][No]={{0,2},{0,1}};
   int B[No][No]={{0,1},{1,0}};
   int C[No][No];
   mat_sum(A,B,C,No);
   return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.