刚刚学习c++,一个求二维数组中的最大值并输出它的行号和列号,编的程序与课本上的没有差别,在输入数据后出现了结果不正确,不知怎么回事,请教各位大佬:
这是源代码:
#include<iostream>
using namespace std;
int main(){
int i,j,row,colum,max;
int a[3][4];
for(i=0;i<3;i++)
for(j=0;j<4;j++)
cin>>a[3][4];
max=a[0][0];
row=0,colum=0;
for(i=0;i<3;i++)
for(j=0;j<4;j++)
if(max<a[i][j])
{ max=a[i][j];
row=i;colum=j;
}
cout<<"\nmax="<<max<<",row="<<row<<",colum"<<colum<<endl;
return 0;
}
下面是输出的结果:
