| | |
Matrix Multiplication using Multi-Dimensional Arrays
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
First of all replace
Here in second line you are multiplying two array members which haven't got their value yet. You're taking values for different cells. Better take inputs earlier than start multiplying matrices or take it like
M[i][j] = m1[i][k]*m2[k][j]; with M[i][j] += m1[i][k]*m2[k][j]; . See the algorithm in above post, for explanation. Also dont forget to set M[i][j] value to 0 before running third loop. C++ Syntax (Toggle Plain Text)
infile >> m1[i][j] >> m2[i][j]; M[i][j] += m1[i][k]*m2[k][j];
Here in second line you are multiplying two array members which haven't got their value yet. You're taking values for different cells. Better take inputs earlier than start multiplying matrices or take it like
infile >> m1[i][k] >> m2[k][j] but wouldnt it be a bit awkward
Last edited by vishesh; Apr 5th, 2009 at 5:18 am.
Well, thanks but I think k shouldn't have a value. It’s basically 0 and later it's used for increment only.
I've also added that += and your infile method, but no difference.
I've also added that += and your infile method, but no difference.
Religion is a way of austerity and a mental self-tranquilizer which is associated with numerous cultures. One cannot deny that Moses predominate Jewish over other believers, while Mohammad calls Muslims to be the ones who excel in humanity and still they are the messengers sent from one God, postulating the impacts of religion and ideology on genetics?
Oops...I just missed a point in previous post. Anyway the loop gotta look like this.
> your infile method
That method I dont suggest. Take matrices values rows by rows only, so that there isnt any confusion.
cpp Syntax (Toggle Plain Text)
//take matrices values before starting for (int i=0; i<6; i++) { for (int j=0; j<6; j++) { M[i][j] = 0; for (int k=0; k<6; k++) { M[i][j] += m1[i][k] * m2[k][j]; } cout << M[i][j] << " "; // this is what i missed to tell } cout<<endl; }
> your infile method
That method I dont suggest. Take matrices values rows by rows only, so that there isnt any confusion.
Last edited by vishesh; Apr 5th, 2009 at 11:32 am.
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: solution for 3 programs
- Next Thread: Implementing Linked List iterator, gcc is acting wierd
Views: 2931 | Replies: 12
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






