449,353 Members | 1,237 Online Need help? Post your question and get tips & solutions from a community of 449,353 IT Pros & Developers. It's quick & easy.

# Help with a Matrix Multiplication program

 P: 1 Ok, I have an assignment to write a program that multiplies two matrices. The matrices dimensions will be user defined as well as the numbers (floating point values) inside of them. The program must check to see if the two matrices are able to be multiplied. This is the code that I have so far: #include "stdafx.h" #include using namespace std; void main() { int row1, row2, col1, col2 = 0; cout << "This program will multiply two matrices that you create. Enter in the number of rows in the first matrix: "; cin >> row1; cout <<"Now please enter in the number of columns: "; cin >> col1; cout << "Please enter the number of rows in the second matrix: "; cin >> row2; cout << "Please enter in the number of columns: "; cin >> col2; if(col1 != row2) { cout << "in order to multiply two matrices the number of columns in the first matrix must match the number of rows in the second << endl << Enter in the number of rows in the first matrix: "; cin >> row1; cout <<"Now please enter in the number of columns: "; cin >> col1; cout << "Please enter the number of rows in the second matrix: "; cin >> row2; cout << "Please enter in the number of columns: "; cin >> col2; } } Now where I get confused is creating the arrays for the two matrices. The professor says that they must be dynamically allocated and they must be 1-dimensional arrays. This is his advice on how to do that: [row][col] -> [row*rowSize + col] I don't quite understand what exactly that statement means, any explanation on that would be appreciated. Dec 10 '07 #1 