问题
输入一个3行4列的数组,找出该数组中绝对值最大的元素、输出该元素及其两个下标值。如有多个输出行号最小的,还有多个的话输出列号最小的。
做法一
#include
#include
using namespace std;
int main()
{
int a[3][4];
int i,j,m=0,x,y;
for(i=1;i<=3;i++)
{
for(j=1;j<=4;j++)
{
cin>>a[i][j];
if(m<abs(a[i][j]))
{
m=abs(a[i][j]);
x=i,y=j;
}
}
}
cout<<m<<' '<<x<<' '<<y<<' ';
return 0;
}
做法二
#include
#include
using namespace std;
int main()
{
int a[3][4];
int i,j,m=0,x,y;
for(i=0;i
{
for(j=0;j
{
cin>>a[i][j];
if(m<abs(a[i][j]))
{
m=abs(a[i][j]);
x=i+1,y=j+1;
}
}
}
cout<<m<<' '<<x<<' '<<y<<' ';
return 0;
}