array within array

I want to store an array within an array.

e.g
int small_array[3] = {1, 2, 3}
int small_array1[3] = {2, 1, 5}
int small_array2[3] = {4, 1, 2}

i want to store those 3 array into another array let's call it
Big_array[3] = {small_array[3], small_array1[3], small_array2};

then i want to run a selection sort to see which array has min/max Sum
in this case small_array3=[3] will be min because it only sums up to 6. I know how to run sorts in array, but the problem is i need to recognize it by the sum of the little array first that's what i'm stuck at.
1
2
3
4
5
int myarray[3][3] = {
	{1,2,3},
	{2,1,5},
	{4,1,2}
};
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int Big_array[3][3] = {
  {1, 2, 3},
  {2, 1, 5},
  {4, 1, 2}
};

int sums[3];
for( int i = 0; i < 3; i++ ) {
  sums[i] = 0;
  for( int j = 0; j < 3; j++ )
    sums[i] += Big_array[i][j];
}

//now sort though sums 

http://cplusplus.com/doc/tutorial/arrays/

PS: Lol, Acr beet me to it...
Last edited on
no no,so what if i want to add another array? like small_array3?
 
int Big_array[4][3]; //4 arrays, each of length 3 

** http://cplusplus.com/doc/tutorial/arrays/ **
( http://cplusplus.com/reference/stl/vector/ )
Last edited on
no, that is not what i meant, i want it to be int big_array[x][3] where x is what the user choose.
search for 'dynamic array' ;)
1
2
3
4
5
6
7
8
9
10
11
//make a 2-D array, size: x by 3
int **big_array = new *int[x];
for( int i = 0; i < x; i++ )
  big_array[i] = new int[3];

... //do stuff

//delete the 2-D array
for( int i = 0; i < x; i++ )
  delete[] big_array[i];
delete[] big_array;
Topic archived. No new replies allowed.