Saturday, August 27, 2011

How to calculate Sum of two matrix using C++.


//How to calculate Sum of two matrix using C++.
#include<iostream.h>
#include<conio.h>
void main()
{
 int a[10][10], b[10][10] , c[10][10];
 int i, j, m, n;
 clrscr();
 cout<<endl<<"enter the order of matrix a and b: ";
 cin>>m>>n;
 cout<<endl<<"Elements of a matrix:";
 for(i=0;i<m;i++)
 {
  for(j=0;j<n;j++)
  {
   cin>>a[i][j];
  }
 }
 cout<<endl<<"Elements of b matrix:";
 for(i=0;i<m;i++)
 {
  for(j=0;j<n;j++)
  {
   cin>>b[i][j];
  }
 }
 cout<<endl<<" a  matrix is :"<<endl;
 for(i=0;i<m;i++)
 {
  cout<<endl;
  for(j=0;j<n;j++)
  {
   cout<<" "<<a[i][j];
  }
 }
  cout<<endl<<" b  matrix is :"<<endl;
 for(i=0;i<m;i++)
 {
  cout<<endl;
  for(j=0;j<n;j++)
  {
   cout<<" "<<b[i][j];
  }
 }
  for(i=0;i<m;i++)
 {
  for(j=0;j<n;j++)
  {
   c[i][j]=a[i][j] + b[i][j];
  }
 }
 cout<<endl<<"Sum of two matrix is:"<<endl;
 for(i=0;i<m;i++)
 {
  cout<<endl;
  for(j=0;j<n;j++)
  {
   cout<<" "<<c[i][j];
  }
 }
 getch();
}

Previous Next Home
0 Comments
Comments

Leave a Comment

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Twitter Delicious Facebook Favorites More