Im completely lost on this one

Reply

Join Date: Oct 2004
Posts: 16
Reputation: Alfy is an unknown quantity at this point 
Solved Threads: 0
Alfy Alfy is offline Offline
Newbie Poster

Im completely lost on this one

 
0
  #1
Oct 14th, 2004
i am suppose to multiply the two matrices together using a for loop, but the only way i can figure it out is by using printf( a[0][0] * b[0][0] + a[0][1] * b[1][0]) 4 times to find each piece. Please help.


#include <stdio.h>

int main()
{
int i,j,k;
int a[2][2]={{1,2},{3,2}};
int b[2][2]={{3,4},{2,1}};
int c[2][2];
printf("Matrix A:\n");
for(i=0; i<=1; i++)
{
for(j=0; j<=1; j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
printf("Matrix B:\n");
for(i=0; i<=1; i++)
{
for(j=0; j<=1; j++)
{
printf("%d ",b[i][j]);
}
printf("\n");
}
printf("AxB=Matrix C:\n");

printf("%d ", a[0][0] * b[0][0] + a[0][1] * b[1][0]);
printf("%d \n", a[0][0] * b[0][1] + a[0][1] * b[1][1]);
printf("%d ", a[1][0] * b[0][0] + a[1][1] * b[1][0]);
printf("%d ", a[1][0] * b[0][1] + a[1][1] * b[1][1]);
/* for (j=0; j<1; j++)
{
for (i=0; i<1; i++)
{
c[i][j] = (a[i][j] * b[i][j]) + (a[i][j] * b[i][j]);
printf("%d ", c[i][j]);
}
printf("\n");
}
I couldnt figure out how to set this in a loop to solve for matrixC
*/
system("PAUSE");
return(0);
}
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 9
Reputation: Waskar is an unknown quantity at this point 
Solved Threads: 0
Waskar Waskar is offline Offline
Newbie Poster

Re: Im completely lost on this one

 
0
  #2
Oct 15th, 2004
Try this way:

  1.  
  2. for(i=0;i<2;i++)<blockquote>for(j=0;j<2;j++)<blockquote>for(k=0;k<2;k++)<blockquote>c[i][j] += a[i][k]*b[k][j];
  3. </blockquote></blockquote></blockquote>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC