| | |
Im completely lost on this one
![]() |
•
•
Join Date: Oct 2004
Posts: 16
Reputation:
Solved Threads: 0
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);
}
#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);
}
•
•
Join Date: Oct 2004
Posts: 9
Reputation:
Solved Threads: 0
Try this way:
C Syntax (Toggle Plain Text)
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]; </blockquote></blockquote></blockquote>
![]() |
Similar Threads
- Card game war; completely lost (C++)
- completely lost (Assembly)
- Lost on structs (C++)
- completely lost (C++)
- Help!!!So lost (C++)
- Lost MSN Explorer (Windows Software)
- Completely confused (C)
- Completely Lost : ( Can anyone help (Java)
Other Threads in the C Forum
- Previous Thread: error when compiling murphy's law with gcc
- Next Thread: I would kill for this, just a little bit
| Thread Tools | Search this Thread |
* ansi api array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile createcopyoffile createprocess() csyntax directory dynamic fflush file floatingpointvalidation fork forloop frequency function getlasterror getlogicaldrivestrin givemetehcodez graphics gtkgcurlcompiling gtkwinlinux hardware highest histogram homework i/o ide inches initialization intmain() iso km license linked linkedlist linux linuxsegmentationfault list logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat openwebfoundation pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string suggestions test unix urboc user variable whythiscodecausesegmentationfault win32api windows.h windowsapi





