Comments

Tuesday, August 27, 2013

Adding two matrix using two dimension array

Posted by at 1:54 AM Read our previous post


Suppose A and B are n-elements vector array in memory and X an Y
are scalars. Write a program to find.
a) XA + YB
b) A . B

Test the program using A= (16, -6,7), B=(4,2,-3), X= 2, Y= -5


Source Code;


#include <iostream>
using namespace std;

int main()

{
       int ary1[2][3]={
              {2,3,4},
              {5,6,7},
      
       };
       int ary2[2][3]={
              {8,0,5},
              {5,1,2},
      
       };;
       int ary3[2][3]={
              {6,3,4},
              {2,7,5},
      
       };;

       int x=2,y=5,count1,count2;

       for(count1=0;count1<2;count1++)
       {
       for(count2=0;count2<3;count2++)
       {
       ary1[count1][count2]*x;
      
       ary2[count1][count2]*y;
       }

       }

       for(count2=0;count2<2;count2++)
       {
       for(count2=0;count2<3;count2++)
       {
       ary1[count1][count2]*x+ary2[count1][count2]*y;
       }

       }

       for(count1=0;count1<2;count1++)
       {
       for(count2=0;count2<3;count2++)
       {
       ary3[count1][count2]=ary1[count1][count2]*x+ary2[count1][count2]*y;
       }

       }

       for(count1=0;count1<2;count1++)
       {
       for(count2=0;count2<3;count2++)
       {
              cout<<ary3[count1][count2]<<" , ";
       }
       cout<<endl;

       }



return 0;
}

Output:

No comments:

Post a Comment

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

Popular Posts

Labels

© Codepirate is powered by Blogger - Template designed by Stramaxon - Best SEO Template