# Homework help?

• 03-28-2012
schaney86
Homework help?
So the beginning numbers are laid out like this:
8 0 3 6 3
1 3 1 0 7
2 7 9 4 5
Then I have to print it out to look like:
3 6 3 0 8
7 0 1 3 1
5 4 9 7 2.
This is what I have so far, and i know its not right because i keep getting an error that the program has quit working.
Code:

```void copyB(const int *fromPtr, int rows, int columns, int to[][10]) {     int r;     int c;     for (r =  columns -1; r < rows; r--) {         for (c = 0; c < columns; c++)             to[r][c] = *fromPtr++;     } }```
This is not my major I technically dont even need this class anymore since i switched majors but i dont want to drop it now, so any tips are appreciated. I have to run it against my professors test driver, but i just can get this one to work right.
Thanks for any help!
• 03-28-2012
manasij7479
You don't need to copy it.
Just swap the n'th element of each row with the (columns -n)'th element.(...iterating n over 0 to columns )
• 03-28-2012
whiteflags
Well with the example you showed the function should not do anything. If columns is 5 and rows is 3, then r would = 4. When you enter the for loop, r is not less than rows.
• 03-29-2012
Amin sma
easy! This code works....
Code:

```#include<iostream.h> void main() { int c[3][5]; for(int i=0;i<3;i++) for(int j=0;j<5;j++) cin>>c[i][j]; for(i=0;i<3;i++) {for(int j=4;j>=0;j--) cout<<c[i][j]; cout<<endl;} }```
• 03-29-2012
Salem
@ Amin sma
Note that we're here to help people figure out the answer for themselves.
Not show off by dumping the complete answer at the first opportunity.
• 03-29-2012
GReaper
Which, mind you, doesn't even compile on standard-compliant compilers! :p
• 03-29-2012
iMalc
That solution is wrong in at least three different ways. For starters it should not use a two-dimensional array when a plain 1D array is sufficient.
• 03-30-2012
Amin sma
ok:cool:
• 03-30-2012
überfuzz
Quote:

Originally Posted by iMalc
That solution is wrong in at least three different ways. For starters it should not use a two-dimensional array when a plain 1D array is sufficient.

True, but his array is to[c][r]. You know how it is teachers are always allowed do things like that. ;-)
• 03-30-2012
iMalc
Quote:

Originally Posted by überfuzz
True, but his array is to[c][r]. You know how it is teachers are always allowed do things like that. ;-)

I'm assuming that the decision of the function prototype is his own, and so could be whatever. Afterall, it's doing such a trivial task (reversing an array) that I would not even create a function for it.
Just read in each line and then print it out backwards. Amin got that part right, albeit with missing formatting.
• 03-30-2012
überfuzz
Quote:

Originally Posted by iMalc
Afterall, it's doing such a trivial task (reversing an array) that I would not even create a function for it.

It could pass as an exercise in the array part in some course. Ah well...