how can i organize one dimensional array of data into multidimensional array.
for example:-
1
2
1
2
1
2
.
.
.
to
1 2 1 2
1 2 1 2
....
i'm using C++ Builder.
thanks..
how can i organize one dimensional array of data into multidimensional array.
for example:-
1
2
1
2
1
2
.
.
.
to
1 2 1 2
1 2 1 2
....
i'm using C++ Builder.
thanks..
ggCode:int a[5][5] = { {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5}, };
This may not be entirely correct, but something along these lines:
edit: this is in c, I didn't realise it was the c++ board. oh well.Code:#include <stdio.h> int main(void) { int oned[9] = { 25, 10, 25, 10, 25, 10, 25, 10, 25 }; int twod[3][3]; int i, x = 0, y = 0; for ( i = 0; i < 9; i++ ) { twod[x][y] = oned[i]; x ++; if (x == 3) { x = 0; y ++; } } return 0; }
Last edited by Brian; 11-02-2003 at 05:10 PM.
but...if i want to make it as 400x400? since i have a large set of data...
Code:#include <stdio.h> int main(void) { int oned[160000] = { ... }; int twod[400][400]; long i; int x = 0, y = 0; for ( i = 0; i < 160000; i++ ) { twod[x][y] = oned[i]; x ++; if (x == 400) { x = 0; y ++; } } return 0; }
Last edited by Brian; 11-02-2003 at 05:23 PM.
thanks for your help brian...