question on multiplying 2D arrays
I am having trouble writing a function to multiply two matricies together. Here is what I have so far, what needs to be done? The fxn is called matrixMultiply. Another question on my printArray fxn is how can I make it so that there are spaces between the numbers?
Code:
//Name: Joseph Valenzuela
//Date: April 22, 2003
//Purpose: Matrix multiplication
#include <iostream.h>
const int MAX_ROWS = 10;
const int MAX_COLS = 10;
// Precondition: None
// Postcondition: Cells of the matrix have been filled with
// data entered at the keyboard. Rows and Cols return the
// actual number of rows and columns.
void readArray(int nums[][MAX_ROWS], int& rows, int& cols);
//Postcondition: Prints the array by rows
void printArray(int array[][MAX_COLS], int rows, int cols);
void main()
{
int array2d[MAX_ROWS][MAX_COLS];
int num_rows=0,num_cols=0;
readArray(array2d,num_rows,num_cols);
printArray(array2d,num_rows,num_cols);
readArray(array2d,num_rows,num_cols);
printArray(array2d,num_rows,num_cols);
}
void readArray(int nums[][MAX_ROWS], int& rows, int& cols)
{
// Accept # of rows, must be from 1-MAX_ROWS
do
{
cout << "Enter the number of rows: ";
cin >> rows;
if (rows <= 0 || rows > MAX_ROWS)
cout << "Must be between 1 and " << MAX_ROWS << endl;
} while (rows <= 0 || rows > MAX_ROWS);
// Accept # of columns, must be between 1 and MAX_COLS
do
{
cout << "Enter the number of columns: ";
cin >> cols;
if (cols <= 0 || cols > MAX_ROWS)
cout << "Must be between 1 and " << MAX_COLS << endl;
} while (cols <= 0 || cols > MAX_COLS);
// Prompt user and accept all matrix values
for (int i=0; i<rows; i++)
for (int j=0; j<cols; j++)
{
cout << "[" << i << "," << j << "]: ";
cin >> nums[i][j];
}
}
void printArray(int array[][MAX_COLS], int rows, int cols)
{
int x,y;
for(x=0; x<rows; x++)
{
for(y=0; y<cols; y++)
cout << array[x][y];
cout << endl;
}
}
/*int matrixMultiply(int array[][MAX_ROWS], int& rows, int& cols)
{
for(int i; i<rows; i++) //for each row i in matrix1 do...
for(int j; j<cols; j++) //for each column j in matrix2 do...
forint(k; k<cols; k++)//for each column k in matrix1 do...
//increase matrix3[i,j] by matrix1[i,k]*matrix2[k,j]*/