Question: I have some errors in my program #include using namespace std; int main() { cout < < Enter no of row of matrix : ;
I have some errors in my program
#include
int main() {
cout << "Enter no of row of matrix : "; int row; cin >> row;
cout << "Enter no of column of matrix:"; int col; cin >> col;
float a[row][col], b[row][col]; // error
//taking input of matrix1 cout << "Enter the elements of matrix 1-->" << endl; for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
cin >> a[i][j];
}
}
//taking input of matrix2 cout << "Enter the elements of matrix 2-->" << endl; for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
cin >> b[i][j];
}
}
float pro[row][col]; // error
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
pro[i][j] = 0;
}
}
//multiplying the given matrix for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
for (int k = 0; k < col; k++) { pro[i][j] += a[i][k] * b[k][j]; }
}
}
cout << "---matrix 1---" << endl; for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
cout << a[i][j] << " ";
} cout << endl;
}
cout << "---matrix 2---" << endl; for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
cout << b[i][j] << " ";
} cout << endl;
}
cout << "---product---" << endl; for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
cout << pro[i][j] << " ";
} cout << endl;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
