请编写一个函数fun,函数的功能是:求出N×M整型数组的最大元素及其行下标和列下标,(如果最大元素不唯一,选择位置在最前面的一个)。
例如:输入的数组为:
1 2 3
4 15 6
12 18 9
10 11 2
求出的最大数为18,行下标为2,列下标为1.
#include
#define N 4;
#define M 3;
int fun(int a[N][M])
{
int i,j,m=0,n=0,max;
max=a[0][0];
for(i=0;i
for(j=0;j
if(max {
max=a[i][j];
m=i;
n=j;
}
}
}
printf("最大数为%d,行下标为%d,,列下标为%d.",max,m,n);
return 0;
}
int main()
{
int i,j,a[N][M];
for(i=0;i
fun(a);
return 0;
}
下面是电脑给的调试结果。
: error C2143: syntax error : missing ']' before ';'
: error C2143: syntax error : missing ')' before ';'
: error C2059: syntax error : ']'
: error C2059: syntax error : ']'
: error C2059: syntax error : ')'
: error C2143: syntax error : missing ']' before ';'
: error C2143: syntax error : missing ';' before ']'
: error C2143: syntax error : missing ';' before ']'
: error C2143: syntax error : missing ')' before ';'
: error C2059: syntax error : ')'
: error C2143: syntax error : missing ';' before 'for'
: error C2143: syntax error : missing ')' before ';'
: error C2059: syntax error : ')'
: error C2146: syntax error : missing ';' before identifier 'scanf'
: error C2109: subscript requires array or pointer type
: error C2102: '&' requires l-value
执行 cl.exe 时出错.