invalid types `int[int]' for array subscript
发布网友
发布时间:2024-09-28 08:57
我来回答
共2个回答
热心网友
时间:2024-09-29 17:23
你的代码中出现了两个a,一个是数组名,一个是int型变量。改变其中一个即可,修改后的代码如下:
#include <iostream>
using namespace std;
int main()
{
int m,n,i,j,k;
cout<<"Please input m,n:"<<endl;
cin>>m>>n;
cout<<"Please input array:"<<endl;
int arr[m][n];
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
cin>>arr[i][j];
}
}
for (i=0;i<m;i++)
{
int biggest=0,a=0,b=0,small=10;
bool flag=true;
for(j=0;j<n;j++)
{
if (arr[i][j]>biggest)
{
a=i,b=j,biggest=arr[i][j];
}
}
for(k=0;k<m;k++)
{
if(biggest>arr[k][b])
{
flag=false;
}
if (flag=true)
{
cout<<"mat["<<a<<"]["<<b<<"]="<<arr[a][b]<<endl;
}
}
}
return 0;
}
热心网友
时间:2024-09-29 17:21
#include <iostream>
using namespace std;
int main()
{int m,n,i,j,k;
cout<<"Please input m,n:"<<endl;
cin>>m>>n;
cout<<"Please input array:"<<endl;
int **a;
a = new int*[m]; //这样开辟空间
for (i=0;i<m;i++){
a[i] = new int[n];
for (j=0;j<n;j++){
cin>>a[i][j]
;}
}
for (i=0;i<m;i++){
int biggest=0,a1=0,b=0,small=10; //变量a和数组名重了
bool flag=true;
for(j=0;j<n;j++){if (a[i][j]>biggest){a1=i,b=j,biggest=a[i][j];}}
for(k=0;k<m;k++){if(biggest>a[k][b]){flag=false;}
if (flag=true){cout<<"mat["<<a1<<"]["<<b<<"]="<<a[a1][b]<<endl;}
}
}}