[英]Can anyone explain why am i getting “expression must have pointer to object type” in the following code:
#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]);
它在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在第 35 行添加{
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.