Friday, 14 March 2014

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 a[10][10],b[10][10],c[10][10],i,j;
  clrscr();
  printf("\n Enter the elements of a: ");
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  scanf("%d",&a[i][j]);
}
  printf("\n");
}
  printf("\nEnter the elements of b: ");
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  scanf("%d",&c[i][j]);
}
  printf("\n");
}
  printf("\n Entered elements of a is:\n");
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  printf("\t%d",a[i][j]);
}
  printf("\n");
}
  printf("\nEntered elements of b is:\n");
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  printf("\t %d",b[i][j]);
}
  printf("\n");
}
  printf("\nAddition of matrix is: ");
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  c[i][j]=a[i][j]+b[i][j];
}
  printf("\n");
}
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  printf("\t %d",c[i][j]);
}
  printf("\n");
}
  getch();
}

//OUTPUT:

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

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

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

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

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

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.

 
Copyright © 2013. BloggerSpice.com - All Rights Reserved
Author: MohammadFazle Rabbi | Powered by: Blogger
Designed by: Blogger Spice
^