"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Thursday, February 18, 2010

Write a program to obtain the product of the following matrices:

           5    9    -2
A =      8    0    5
           0    2    8




          2  4
B =     0   1
          1  3


A x B =      8     23
                21    47
                8     26
          


#include<iostream.h>
#include<conio.h>
#include<process.h>


void main()
{
clrscr();


int A[3][3] = { 5, 9, -2,
                     8,0,5 ,
                     0,2, 8 };


int B[3][2] = { 2,4 ,
                      0 , 1,
                      1,3 } ;


int P[3][2] , i, j, k;


/*  ......Product ...... */


for(i = 0; i< 3 ; i++)
for(j = 0 ; j< 2 ; j++)
{
  P[i][j] = 0;
for(k = 0; k< n ; k++)
 P[i][j] = P[i][j] + A[i][k] * B[k][j];
}




cout<< "\n Matrix A : \n ";


for( i =0; i< 3 ; i++)
{  for(j = 0; j< 3 ; j++)
       cout<<  A[i][j];
   cout<< endl;
}


cout<< "\n Matrix B: \n ";




for( i =0; i< 3 ; i++)
{ for(j = 0; j< 2 ; j++)
     cout<<  B[i][j];
cout<< endl;
}


cout<< "\n  Product AXB  : \n ";




for( i =0; i< 3 ; i++)
{ for(j = 0; j< 2 ; j++)
   cout<< P[i][j];
cout<< endl;
}


getch();


}

No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.