You are on page 1of 2

#include <stdio.

h>
#define SZ 10
void addMatrices(int [][SZ], int [][SZ], int,int);
int (*(addMatrixReturn)(int [][SZ], int [][SZ], int,int))[SZ];
void inputMatrix( int [][SZ], int, int);
void printMatrix(int [][SZ], int, int );

int main()
{
int i,j, r1, c1, r2, c2;
int M1[SZ][SZ], M2[SZ][SZ], (*M)[SZ];
printf("\nEnter the number of rows and colums of Matrix 1");
scanf("%d%d",&r1,&c1);
printf("\nEnter the number of rows and colums of Matrix 2");
scanf("%d%d",&r2,&c2);
if(r1 == r2 && c1 == c2) {
printf("\nEnter the element of first matrix:");
inputMatrix(M1, r1, c1);
printf("\nEnter the second matrix:");
inputMatrix(M2, r2, c2);
addMatrices(M1, M2, r1, c1);

M = addMatrixReturn(M1, M2, r1, c1);


printf("\n The resultant Matrix is:\n");
printMatrix(M, r1, c1);
}
else
printf("\n Addition is not possible");
return 0;
}

void inputMatrix( int M[][SZ], int r, int c) {


int i, j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&M[i][j]);
}
printf("\n");
}
}

void addMatrices(int M1[][SZ], int M2[][SZ], int r1, int c1) {


int M [SZ][SZ], i,j;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
M[i][j] = M1[i][j] + M2[i][j];
}
}
printf("\n The Resultant Matrix is:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("%d ", M[i][j]);
}
printf("\n");
}
}
int (*(addMatrixReturn)(int M1[][SZ], int M2[][SZ], int r1, int c1))[SZ]{
int (*M)[SZ], i,j;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
M[i][j] = M1[i][j] + M2[i][j];
}
}
return M;
}

void printMatrix( int M[][SZ], int r, int c){


int i, j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d ", M[i][j]);
}
printf("\n");
}
}

You might also like