#include<iostream>
#include<conio.h>
#include<array>
using namespace std;
int main(){
system("cls");
int n, l, m;
int a[100][100], b[100][100], m[100][100];
//inputing
cout<<"For the multiplication of the matrices NxL & LxM: \n";
cout<<"Enter N: ";
cin>>n;
cout<<"Enter L: ";
cin>>l;
cout<<"Enter M: ";
cin>>m;
cout<<"Enter the first matrix: ";
for(int i=0; i<n; i++){
for(int j=0; j<l; j++){
cout<<i<<":";
cin>>a[i][j];
}
cout<<" \n";
}
cout<<"Enter the second matrix: ";
for(int i=0; i<l; i++){
for(int j=0; j<m; j++){
cout<<i<<":";
cin>>a[i][j];
}
cout<<" \n";
}
//multiplying
for(int i=0; i<n; i++)
for(int j=0; j<l; j++){
m[i][j] = a[i][j]*b[j][i]);
}
}
getch();
system("cls");
return 0;
}
I am trying to multiply two matrices in this code, but this statement is creating a major problem. Please tell how to solve this error. it is giving me error in the line
m[i][j] = a[i][j]*b[j][i]);
Your code previously had few minor bugs, like missing }
. Here I have corrected it.
#include<iostream>
#include<array>
#include<conio.h>
using namespace std;
int main(){
system("cls");
int n, l, m;
int a[100][100], b[100][100], ar[100][100];
//inputing
cout<<"For the multiplication of the matrices NxL & LxM: \n";
cout<<"Enter N: ";
cin>>n;
cout<<"Enter L: ";
cin>>l;
cout<<"Enter M: ";
cin>>m;
cout<<"Enter the first matrix: ";
for(int i=0; i<n; i++){
for(int j=0; j<l; j++){
cout<<i<<":";
cin>>a[i][j];
}
cout<<" \n";
}
cout<<"Enter the second matrix: ";
for(int i=0; i<l; i++){
for(int j=0; j<m; j++){
cout<<i<<":";
cin>>a[i][j];
}
cout<<" \n";
}
//multiplying
for(int i=0; i<n; i++){
for(int j=0; j<l; j++){
ar[i][j] = a[i][j]*b[j][i];
}
}
getch();
system("cls");
return 0;
}
Things I have changed:-
{
at line no 35
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.