Please, I need help in finding the sum of two matrices using pointers. Thanks.

4
Contributors
4
Replies
6
Views
8 Years
Discussion Span
Last Post by xavier666

Q: Do you know how to do it on paper?
(a) No: Go figure that out before trying to write code.
(b) Yes: Show us your code, and be more freaking specific about what problem you're having.

Since you didn't post any code, I'll assume your answer to the question is (a). All too often we get people who have no idea how to solve the problem and rush off to write code. It's like building a bridge without a blueprint. Stupid.

Q: Do you know how to do it on paper?
(a) No: Go figure that out before trying to write code.
(b) Yes: Show us your code, and be more freaking specific about what problem you're having.

Since you didn't post any code, I'll assume your answer to the question is (a). All too often we get people who have no idea how to solve the problem and rush off to write code. It's like building a bridge without a blueprint. Stupid.

I have tried but can't and that is why I brought it here

``````do 66 i=1,3
do 66 j=1,3

do 66 k=1,3
c[i,j] = a[i,k]  *   b[k,j]
66 continue``````

now convert to pointers

``````a[1,1]    in pointers      *(pa+0+0)

a[1,3] in pointers *(pa +(i-1) * 3*( j-1))``````

Assume matrices stored in column order
a[i,j]
1 1 *(pa)
2 1 *(pa + 2-1 + 3*(1-1) = *(pa+1)
3 1 *(pa + 3-1 + 3*(1-1) = *(pa+2)
1 2 *(pa + 1-1 + 3*(2-1) = *(pa+3)
2 2
3 2
1 3
2 3
3 3

Edited by peter_budo: Keep it Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

I have tried but can't

Show us how much or whatever you have tried.
Before moving into such questions on programming, think how you would solve the problem sequencially.
Can you atleast do it without pointers, using array-index?

Assume matrices stored in column order

In C, 2D Arrays lements are stored in Row-major format. As per my knowledge, column-major is only used in Fotran and MATLAB (and this is the C forum)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.