一个求二维数组最大值的问题,求教大佬解惑

言西早l 2020-05-18 09:43:16
刚刚学习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;
}
下面是输出的结果:
...全文
56 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
chxchxkkk 2020-05-18
  • 打赏
  • 举报
回复
cin>>a[3][4]; ==》》 a[i][j]
Simple-Soft 2020-05-18
  • 打赏
  • 举报
回复
#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[i][j];

max=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;
}

33,322

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧