Write a C program for addition of two matrices.
Answers
# include <stdio.h>
# include <conio.h>
void main ( )
{
int i, j, a[3][3], b[3][3], sum[3][3];
clrscr ( ) ;
printf ("Enter the elements of 1st array .\n") ;
for (i=1;i<=3;i++)
{
for (j=1;j<=3;j++)
{
scanf ("%d", &a[i][j]) ;
}
}
printf ("Enter the elements of 2nd array .\n") ;
for (i=1;i<=3;i++)
{
for (j=1;j<=3;j++)
{
scanf ("%d", &b[i][j]) ;
}
}
printf ("The sum of both the matrices are: \n") ;
for (i=1;i<=3;i++)
{
for (j=1;j<=3;j++)
{
sum[i][j] = a[i][j] + b[i][j];
printf ("%d\t", sum[i][j]) ;
}
printf ("\n") ;
}
getch ( ) ;
}
Hope it helps!
Mark me as Brainlist!
Addition of two matrices in c programming
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int mat1[2][3],mat2[2][3],mat3[2][3],i,j;
printf("Enter the elements of matrix1\n");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&mat1[i][j]);
}
}
printf("the elements of the matrix2\n");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&mat2[i][j]);
}
}
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
mat3[i][j]=mat1[i][j]+mat2[i][j];
}
}
printf("\nthe result of matrix is\n");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
printf(" %d",mat3[i][j]);
}
printf("\n");
}
getchar();
}