查找二维数组中的最大值及其行下标

题目

img

img


我的答案


int  FindMaxbyCol(int *q,int row,int col,int *maxRow,int *maxCcol)
{
    int m,n;
    int max=q[0][0];
    for(int i=0;ifor(int j=0;jif(max<q[i][j])
            {
                max=q[i][j];
                *maxRow=i;
                *maxCcol=j;
            }
        }
    }
}

请问我是哪些地方写错了啊?谢谢

FindMaxbyCol函数的第一个参数是int *,你在代码里 用q[][]这种写法是不对的,代码修改如下:


int  FindMaxbyCol(int* q, int row, int col, int* maxRow, int* maxCcol)
{
    //int m, n;
    int max = q[0];
    for (int i = 0; i < row; i++)
    {
        for (int j = 0; j < col; j++)
        {
            if (max < q[i*col+j])
            {
                max = q[i * col + j];
                *maxRow = i;
                *maxCcol = j;
            }
        }
    }
}

m n是什么
应该用row col,而不是 m n

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632