0% found this document useful (0 votes)
7 views3 pages

ADD TWO MATRIX Coding .

Uploaded by

deepandeepan4321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

ADD TWO MATRIX Coding .

Uploaded by

deepandeepan4321
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

ADD TWO MATRIX

#include <stdio.h>
void matrixAdd(int m1[3][3], int m2[3][3], int res[3][3]);
int main()
{
int r=3,c=3;
int i,j;
int x[3][3], y[3][3], res[3][3];
printf("Enter elements in first matrix of size %dx%d: \n", r, c);
for (i = 0; i < r; i++)
{
for (j = 0; j < c; j++)
{
scanf("%d", (*(x + i) + j));
}
}
printf("\nEnter elements in second matrix of size %dx%d: \n", r, c);
for (i = 0; i < r; i++)
{
for (j = 0; j < c; j++)
{
scanf("%d", (*(y + i) + j));
}
}
matrixAdd(x, y, res);
printf("\nSum of first and second matrix: \n");
for (i = 0; i < r; i++)
{
for (j = 0; j < c; j++)
{
printf("%d ", *(*(res + i) + j));
}
printf("\n");
}
return 0;
}
void matrixAdd(int x[3][3], int y[3][3], int res[3][3])
{
int i, j;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
*(*(res + i) + j) = *(*(x + i) + j) + *(*(y + i) + j);
}
}
}
OUTPUT:
Enter elements in first matrix of size 3x3 ;
1 2 3
4 5 6
7 8 9
Enter elements in second matrix of size 3x3 ;
9 8 7
6 5 4
3 2 1
Sum of first and second matrix ;
10 10 10
10 10 10
10 10 10

You might also like