Anyone of you guys can help me writing a programe usuing the foor loop twice or more and that will add the two matrices (A):- |A11 A12 . . .A1m| | | |A21 . | m*m | . | |Am1 . | and (B):- |B11 B12 . . .B1n| | | |B21 . | m*m | . | |Bn1 . | M: POSITIVE INTEGER Please send it to my email ( maxe5000@hotmail.com ) and Thanx very much.
Anyone of you guys can help me writing a programe usuing the foor loop twice or more and that will add the two matrices You will need to make that clearer, possibly by using pre and /pre Please send it to my email The purpose of a forun is that everyone can see the answer. Erik
well..u can consider me stupid in C++ and I needed this solution for some important reason..someone has directed me to this site and told me that there should be someone there who can help me I dont know how to fix it more than I did Ill try to retype it clearer in a matrix shape (A):- |A11 A12 . . .A1m| |................| |A21.............| m*m |................| |Am1.............| and (B):- |B11 B12 . . .B1n| |................| |B21.......... ..| m*m |................| |Bn1.............| these are the two matrices..and I just need a simple programe using the ( for loop ) for adding these two matrices together. M: POSITIVE INTEGER
I will assume that the elements of your matrices A and B are integers, since you didn't say otherwise, that a constant "m" is #defined somewhere for their dimension, and that they are within scope somehow (via extern, etc.) Also, I'm assuming that their dimension is less than 65536.
unsigned int C[m][m]; unsigned int i; unsigned int j; for (i = 0; i < m; i++) { for (j = 0; j < m; j++) { C[i][j] = A[i][j] + B[i][j]; } }
"There... now your teacher will think you know how to do it." You could also try: http://www.essayrelief.com
Thanx Jay Daniel Thanx A.W. Neil :=) I hope you guys would accept me as a new friend in this message board.
Maxie, At the expense of being a bit on the pedantic side, posting homework questions on forums generally isn't a great way to make friends. Unfortunately, people who do what you've done sometimes end up getting jobs as programmers or embedded systems engineers. Further, sometimes people such as Andy and myself end up having to maintain code written by people who've done this. That generally makes our live difficult. The upshot of this is: it's a better idea to really ask about how "for" loops work, etc. than to ask for an answer to the problem. I doubt you really learned much from reading my post.
"posting homework questions on forums generally isn't a great way to make friends" Neither is it a terribly effective way for you to achieve the objective of the excercise - which is for you to practice what you have been taught in class. When it comes to exam time, you will not be able to post the questions on a forum and wait for a reply - you wil have to do it all by yourself. Similarly when it comes to interview time for a job. You need to practice the art of sitting down, analysing a problem, and designing a solution. The only way to gain this experience is to actually do it yourself. It's the same as physical exercise - you won't build any muscles unless you actually do the workout! For this particular assignment, you should start by thinking how you would do matrix addition by hand: it's a matter of considering each element in a row, and then repeating that for each row. The two occurrences of "for each" just then should immediately suggest to you where the two 'for' loops should come. Now that Jay has given you a solution, why don't you try writing out a plain-English description of what it actually does? At least that would give you some exercise. And beware - teachers can read forums, too: http://www.8052.com/forum/read.phtml?id=60122