如题,矩阵行列之和放入另外另个数组,并且要求输出时,每行之后紧跟行的和,列下面紧跟列之和
具体代码如下:
1 #include<iostream> 2 using namespace std; 3 4 int main() 5 { 6 int i, j; 7 int A[5][5] = { 23, 45, 6, 1, -3, 8 4, 5, 233, 456, 0, 9 3, 56, 78, -356, 5, 10 6, 777, 8, 89, 9, 11 3, 6, 8, 9, 90 }; 12 13 int B[5] = { 0 }; 14 int C[5] = { 0 }; 15 16 for (i = 0; i < 5; i++) 17 { 18 for (j = 0; j < 5; j++) 19 { 20 B[i] = A[i][j] + B[i];//每次内循环可以将行和计算出来 21 C[j] = A[i][j] + C[j];//每次内循环,将每行依次填入C数组,然后靠外循环每次在相应位置加上去,就得到了列之和 22 } 23 } 24 25 for (i = 0; i < 5; i++) 26 { 27 for (j = 0; j < 5; j++) 28 { 29 cout << A[i][j] << " "; 30 } 31 cout << B[i]; 32 cout << endl; 33 } 34 for (i = 0; i < 5; i++) 35 { 36 cout << C[i] << " "; 37 } 38 cout << endl; 39 return 0; 40 }