jbeith
January 21st, 2009, 02:55 AM
cout << "Enter Dimensions of first matrix" << endl;
cout << "Rows: ";
cin >> rows1;
cout << "Columns: ";
cin >> cols1;
cout << "Enter Dimensions of second matrix" << endl;
cout << "Rows: ";
cin >> rows2;
cout << "Columns: ";
cin >> cols2;
if(cols1 == rows2){
int matrix1[20][20];
int matrix2[20][20];
int matrix3[20][20];
cout << "MATRIX 1" << endl;
for(int i=0;i<rows1;++i){
for(int j=0;j<cols1;++j){
cout << "Enter value for Row ";
cout << i;
cout << ", Column ";
cout << j;
cout << ": ";
cin >> matrix1[i][j];
}
}
cout << "MATRIX 2" << endl;
for(int i=0;i<rows2;++i){
for(int j=0;j<cols2;++j){
cout << "Enter value for Row ";
cout << i;
cout << ", Column ";
cout << j;
cout << ": ";
cin >> matrix2[i][j];
}
}
cout << "CALCULATING..." << endl;
int x = 0;
for(int k=0;k<rows1;++k){
for(int i = 0;i<cols2;++i){
for(int j = 0;j<rows2;++i){
matrix3[k][i] += matrix1[k][j]*matrix2[j][i];
}
}
}
cout << "NEW MATRIX" << endl;
for(int i=0;i<rows1;++i){
for(int j=0;j<cols2;++j){
cout << matrix3[i][j];
cout << " ";
}
cout << "" << endl;
}
I get "Stack around the variable "***" was corrupted" for variables rows 1, rows 2, cols1, cols2, matrix1,matrix2.matrix3. Anyone know exactly it's having problems with in it?
cout << "Rows: ";
cin >> rows1;
cout << "Columns: ";
cin >> cols1;
cout << "Enter Dimensions of second matrix" << endl;
cout << "Rows: ";
cin >> rows2;
cout << "Columns: ";
cin >> cols2;
if(cols1 == rows2){
int matrix1[20][20];
int matrix2[20][20];
int matrix3[20][20];
cout << "MATRIX 1" << endl;
for(int i=0;i<rows1;++i){
for(int j=0;j<cols1;++j){
cout << "Enter value for Row ";
cout << i;
cout << ", Column ";
cout << j;
cout << ": ";
cin >> matrix1[i][j];
}
}
cout << "MATRIX 2" << endl;
for(int i=0;i<rows2;++i){
for(int j=0;j<cols2;++j){
cout << "Enter value for Row ";
cout << i;
cout << ", Column ";
cout << j;
cout << ": ";
cin >> matrix2[i][j];
}
}
cout << "CALCULATING..." << endl;
int x = 0;
for(int k=0;k<rows1;++k){
for(int i = 0;i<cols2;++i){
for(int j = 0;j<rows2;++i){
matrix3[k][i] += matrix1[k][j]*matrix2[j][i];
}
}
}
cout << "NEW MATRIX" << endl;
for(int i=0;i<rows1;++i){
for(int j=0;j<cols2;++j){
cout << matrix3[i][j];
cout << " ";
}
cout << "" << endl;
}
I get "Stack around the variable "***" was corrupted" for variables rows 1, rows 2, cols1, cols2, matrix1,matrix2.matrix3. Anyone know exactly it's having problems with in it?