Well for example if i have a 3x3 matrix and i read the values 1 2 3 4 5 6 7 8 9 the program should generate 1 2 3 6 9 8 7 4 5..but thats not important since my program works fine.Regarding dynamic allocation.....I think i need to use pointers thats why i said i need a function with this prototype void f (int *a,int m,int n) and not something like i did void f(int a[10][10],int m,int n)..No matter what you change i need to have this prototype void f(int *a,int m,int n) and i dont know how to do that.
A linear block. Literal "10" would be black magic.
If the 2D matrix should have Columns columns and Rows rows, then it must have Columns*Rows cells. You could play with where in array each cell[row, col] is, but lets stick to the traditional row-major.
1 2 3 4 5
size_t Columns = 42;
size_t Rows = 42;
int * foo = new [Columns * Rows];
// use foo
delete [] foo;
Setting values:
1 2 3 4 5
for ( size_t row = 0; row < Rows; ++row ) {
for ( size_t col = 0; col < Columns; ++col ) {
foo[ Columns*row + col ] = rand();
}
}
Ok .I repaired my program and now it looks at it should be but its not working for 3x3 matrices and above and i still dont get it why because i checked every line and my code seems correct.Some help would be really nice
And if you look at my first post the program looks very similar with the last i posted....Why the first works fine since i havent changed much in"for loops"?