Wednesday, 6 February 2013

Write a c program to calculate sum of two mXn matrices & store the result in 3 matrix



#include<stdio.h>
#include<conio.h>
  void main()
{
  int m[10][10],n[10][10],p[10][10],i,j;
  clrscr();
  printf("\nEnter the elements of m: ");
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  scanf("%d",&m[i][j]);
}
  printf("\n");
}
  printf("\nEnter the elements of n: ");
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  scanf("%d",&n[i][j]);
}
  printf("\n");
}
  printf("\nEntered elements of m is:\n");
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  printf("\t%d",m[i][j]);
}
  printf("\n");
}
  printf("\nEntered elements of n is:\n");
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  printf("\t%d",n[i][j]);
}
  printf("\n");
}
  printf("\nAddition of matrix is: ");
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  p[i][j]=m[i][j]+n[i][j];
}
  printf("\n");
}
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  printf("\t%d",p[i][j]);
}
  printf("\n");
}
  getch();
}

//OUTPUT:

//Enter the elements of m:
1
2
3
4
5
6
7
8
9

//Enter the elements of n:
1
2
3
4
5
6
7
8
9

//Entered elements of m is:
      1       2       3
      4       5       6
      7       8       9

//Entered elements of n is:
      1       2       3
      4       5       6
      7       8       9

//Addition of matrix is:
      2       4       6
      8       10      12
      14      16      18

No comments:

Post a Comment