matrix addition in c

PROGRAM:

#include<stdio.h>
#include<conio.h>
int main()
{
 int mata[3][3],matb[3][3],matc[3][3];
 int r,c,k;
 for(r=0; r<3; r++)
 {
  for(c=0; c<3; c++)
  {
    printf(“Enter first matrix : “);
    scanf(“%d”,&mata[r][c]);
  }
 }
 for(r=0; r<3; r++)
 {
  for(c=0; c<3; c++)
  {
    printf(“Enter second matrix : “);
    scanf(“%d”,&matb[r][c]);
  }
 }
 for(r=0; r<3; r++)
{
for(c=0; c<3; c++)
{
matc[r][c]=0;
for(k=0; k<3;k++)
matc[r][c]=mata[r][c] + matb[r][c];
}
}
printf(“New addition matrix : \n”);
for(r=0; r<3; r++)
{
for(c=0; c<3; c++)
printf(” %d”,matc[r][c]);
printf(“\n”);
}
getch();
 return 0;
}
OUTPUT:
Enter first matrix :
1 2 3
  4 5 6
  7 8 9
Enter second matrix :
2 1 7
  4 6 3
  8 1 1
New addition matrix :
3  3  10
  8  11 7
  15 9  10

related links..

Latest posts by admin (see all)

More in sem1
matrix multiplication in c

matrix multiplication in c PROGRAM: #include <stdio.h> void read_matrix(int m2[][3] ) { int i, j; printf("input values for matrix in...

Close