Hi everybody.
Keeping my fingers crossed here, hoping that someone can shed some light
on this problem for me.
I have a function which accepts a 2D array
of 9x9 dimentions.
1 2 3
int array[9][9];
int function(int a[][9])
And i send the array to the function like so:
function(array);
Now, suppose I need to send a 3D array to the same function.
An array of dimentions 5x9x9
3dArray[5][9][9];
How do I send it so that my function iterates through those 5 9x9 arrays?
#include <iostream>
int F( int a[][9] )// find and return the sum of all 81 elements
{
int sum = 0;
for( unsigned i=0; i < 9*9; ++i )
sum += a[i/9][i%9];
return sum;
}
int main()
{
int arr3D[5][9][9];
// initialize the element values
for( unsigned i=0; i < 5*9*9; ++i ) arr3D[0][0][i] = i;// 0-404
// print the sum of each 9x9 array of values
for( unsigned i=0; i < 5; ++i )
cout << "sum = " << F( arr3D[i] ) << endl;
cout << endl;
return 0;
}
Output:
sum = 3240
sum = 9801
sum = 16362
sum = 22923
sum = 29484