How to find product of a row of 2D/Multidimensional array?

How would I find the product of a row of 2D array?

Example:

COLS = 2; ROWS = 3;
int product;

ex: Array[ROWS][COLS];

I want to find the product of the ROW times the COL but cant seem to figure out the code.


1
2
3
4
5
6
7
8
9
  double Data_Array[Num_Data][2];  // For Instance Num_Data is 6;

   for(int x = 0; x < Num_Data; x++)
      for(int y = 0; y < 2; y++)
      {
         xSq = Data_Array[x][x] * Data_Array[x][x]; // Find square of x(rows)
         ySq = Data_Array[x][y] * Data_Array[x][y]; // Find square of y(columns)
         XY = // how do I find the x times the y?
      }
your example is awful

consider the 3x2 matrix
1 2
3 4
5 6
¿what values do you want to multiply?
1 x 2
3 x 4
5 x 6

like that.
your terminology is confusing. What you just described is multiply across columns.

for that you need storage for the results
double result[numrows] = {0};
for(dx = 0; dx < numrows; dx++)
{
result[dx] = array[dx][0]*array[dx][1];
}

or more generally if you have multiple columns or variable #s of columns

for(dx = 0; dx < numrows; dx++)
for (c = 0, result[dx] = 1; c < numcols; c++)
{
result[dx] *= array[dx][c];
}

Last edited on
Topic archived. No new replies allowed.