How to mutiply two matrixes using pointer representation ??
I know well how to do it without pointers....but I am facing difficulty while doing the same with pointers as I am new to it...Please help !
How to mutiply two matrixes using pointer representation ??
I know well how to do it without pointers....but I am facing difficulty while doing the same with pointers as I am new to it...Please help !
" I failed in some subjects in exam , but my friend passed in all . Now he is an engineer in Microsoft and I am the owner of Microsoft !! "
- Bill Gates .
You've been here long enough that you should know to show us your code, and ask specific questions...
We're not going to write code for you.
well I know how to pass an array to another function
like I did here
but to multiply two matrixes I need to send two arrays into a single function using pointers..how to do it ??Code:#include <stdio.h> void display (int *q,int ,int); int main () { int arr[3][3]={ 1,2,3,4,5,6,7,8,9 }; display (&arr[0][0],3,3); return 0 ; } void display (int *q,int row,int col) { int i,j ; printf ("Matrix is : \n"); for (i=0;i<row;i++) { for (j=0;j<col;j++) printf ("%d ",*(q+i*col+j)); printf ("\n"); } printf ("Transpose of the matrix is : \n"); for (i=0;i<row;i++) { for (j=0;j<col;j++) printf ("%d ",*(q+j*col+i)); printf ("\n"); } }
" I failed in some subjects in exam , but my friend passed in all . Now he is an engineer in Microsoft and I am the owner of Microsoft !! "
- Bill Gates .
If you can send one array into a function with one parameter, you can send two arrays into a function using two parameters. The only thing that changes is the amount of pointers in the function prototype.
" I failed in some subjects in exam , but my friend passed in all . Now he is an engineer in Microsoft and I am the owner of Microsoft !! "
- Bill Gates .
Change your function prototype and definition to handle the extra pointer parameter.
Maybe I wasn't clear.
Now you see the difference in the amount of pointers in the prototype.Code:void display (int *q,int ,int, int *p);
Though, if q and p are not guaranteed to have the same dimensions, pass in rows and columns as well.
" I failed in some subjects in exam , but my friend passed in all . Now he is an engineer in Microsoft and I am the owner of Microsoft !! "
- Bill Gates .
Don't forget that matrix multiplication can give you a different shaped matrix back. I think you'll need to return the number rows and cols of the result too. You could just work it out in the calling function, but that's not very clean.
At this point I think I'd create a struct type to hold a matrix's elements and dimensions rather than pass around lots of matrix+row+cols all around the place.