qq_33486292 于 2016.04.02 18:41 提问

c++比较简单的问题，求解！

5个回答

CSDNXIAOD   2016.04.02 18:52

----------------------biu~biu~biu~~~在下问答机器人小D，这是我依靠自己的聪明才智给出的答案，如果不正确，你来咬我啊！

qq423399099      2016.04.02 19:00

minor_sum+=a[m-1][i]应该改为minor_sum+=a[m-i-1][i]

duke_xl   2016.04.02 20:22

qq_20603903   2016.04.02 21:07

`````` int _tmain(int argc, _TCHAR* argv[])
{
int m = 5, n = 5;
int a[5][5] = {0};

int i = 0, j = 0;
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
cin >> a[i][j];
}
}

for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
cout << a[i][j] << " ";
}
cout <<endl;
}

int nMin = a[0][0], nMax = a[0][0];
int nMain_Sum = 0, nMinor_Sum = 0;
int nRowMin = 0, nColMin = 0;
int nRowMax = 0, nColMax = 0;
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
int nTem = a[i][j];
if (nMin > nTem)
{
nMin = nTem;
nRowMin = i;
nColMin = j;
}

if (nMax < nTem)
{
nMax = nTem;
nRowMax = i;
nColMax = j;
}

}

nMain_Sum += a[i][i];
nMinor_Sum += a[m-i-1][i];
}

cout<< "最大值为:" << nMax << "在第" << nRowMax << "行" << "第" << nColMax << "列" << endl;
cout<< "最小值为:" << nMin << "在第" << nRowMin << "行" << "第" << nColMin << "列" << endl;
cout<< "主对角线之和为:" << nMain_Sum <<endl;
cout<< "次对角线之和为:" << nMinor_Sum <<endl;
``````