다음 표의 각 행의 합계, 각 열의 합계를 구하는 프로그램을 작성하세요. main()을 포함하여 3개이상의 함수를 사용하세요.
12 | 56 | 32 | 16 | 98 |
99 | 56 | 34 | 41 | 3 |
65 | 3 | 87 | 78 | 21 |
#include <iostream>
using namespace std;
int main()
{
int arr[][5] = { {12, 56, 32, 16, 98}, {99, 56, 34, 41, 3}, {65, 3, 87, 78, 21} };
for (int i = 0; i < 3; i++) {
cout << "sum of row " << i << ": ";
int sum_row = 0;
for (int j = 0; j < 5; j++) sum_row += arr[i][j];
cout << sum_row << endl;
}
for (int i = 0; i < 5; i++) {
cout << "sum of col " << i << ": ";
int sum_col = 0;
for (int j = 0; j < 3; j++) sum_col += arr[j][i];
cout << sum_col << endl;
}
}
'C++' 카테고리의 다른 글
[C++] 도형 클래스 (0) | 2022.03.24 |
---|---|
[C++] 날짜 클래스 (0) | 2022.03.23 |
[C++] 스마트폰 클래스 (0) | 2022.03.22 |
[C++] 평균, 최대값, 최소값 (0) | 2022.03.20 |
[C++] 비주얼 스튜디오 설치 방법 (0) | 2022.03.19 |