Visual C++ 基礎篇 二維陣列相加後求最大值

兩個二維陣列
a[3][3] = { {5,7,2},{4,8,3},{2,1,2} }
b[3][3] = { {6,2,1},{2,7,9},{4,6,3} }
求相加後,最大值是多少?
蓋棉被 talk543.tw p29.png
#include <iostream>
using namespace std;
void main()
{
int a[3][3] = { {5,7,2},
{ 4,8,3 },
{ 2,1,2 } },
b[3][3] = { { 6,2,1 },
{ 2,7,9 },
{ 4,6,3 } },
i,j,k,l, s[3][3], max = s[0][0];

for (i = 0; i <= 2; i++)
{
for (j=0;j<=2;j++)
{
s<em>[j] = a<em>[j] + b<em>[j];//放入S陣列
cout << s<em>[j] << " ";//將 S陣列秀出
}
cout << endl;
}
for (k = 0; k <= 2; k++) {
for (l = 0; l <= 2; l++) {
cout << "秀出第" << k + 1 << "列第" << l + 1 << "個的數值:" << s[k][l] << endl;
if (s[k][l] > max) {
max = s[k][l];
}
}
}
cout << "最大值:" << max << endl;
system("Pause");
}
已邀請:

要回復主題請先登入註冊