上海,浙东阀门招焊工吗:我做的C++编程题错在哪里?(题目要求是求6个数中最大的数及其位置)

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/29 21:36:12
#include<iostream.h>
int max(int t[][3],int s,int g);
void main()
{ int a,b,c,d,e,f;
cout<<"请输入6个数组成一个二维数组:\n";
cin>>a;
cin>>b;
cin>>c;
cin>>d;
cin>>e;
cin>>f;
int sg[2][3]={{a,b,c},{d,e,f}};
cout<<"The max is"<<max<<endl;
}
int max(int t[][3],int s,int g)
{ int max=0;
int x=0;
int y=0;
for(int i=0;i<s;i++)
for(int j=0;j<g;j++)
if(t[i][j]>max)
{
max=t[i][j];
x=i+1;
y=j+1;
}
cout<<"最大数的行数为"<<x<<"最大数的列数为"<<y<<endl;
return max;
}

#include<iostream.h>
int max(int t[][3],int s,int g);
void main()
{ int a,b,c,d,e,f;
cout<<"请输入6个数组成一个二维数组:\n";
cin>>a;
cin>>b;
cin>>c;
cin>>d;
cin>>e;
cin>>f;
int sg[2][3]={{a,b,c},{d,e,f}};
cout<<"The max is"<<max(sg,2,3)<<endl;
/////////////////////////////////~~~~~~~~~~~
}
int max(int t[][3],int s,int g)
{ int max=0;
int x=0;
int y=0;
for(int i=0;i<s;i++)
for(int j=0;j<g;j++)
if(t[i][j]>max)
{
max=t[i][j];
x=i+1;
y=j+1;
}
cout<<"最大数的行数为"<<x<<"最大数的列数为"<<y<<endl;
return max;
}

原来输出的是max函数的地址。

int sg[2][3]={{a,b,c},{d,e,f}};
这句错了,不能用变量来初始化数组,只能用常量初始化,必须写为

sg[0][0]=a
sg[0][1]=b
....

原来输出的是max函数的地址。
你没有给MAX参数
cout<<"The max is"<<max(sg,2,3)<<endl
这样就行了