Created
February 13, 2025 14:37
-
-
Save vlaleli/5cfbcedfc65ef0e0df44841afbe1a884 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int main() { | |
| const int rows = 3, cols = 4; | |
| int arr[rows][cols] = { | |
| {3, 5, 6, 7}, | |
| {12, 1, 1, 1}, | |
| {0, 7, 12, 1} | |
| }; | |
| int rowSums[rows] = {0}; | |
| int colSums[cols] = {0}; | |
| int totalSum = 0; | |
| for (int i = 0; i < rows; i++) { | |
| for (int j = 0; j < cols; j++) { | |
| rowSums[i] += arr[i][j]; | |
| colSums[j] += arr[i][j]; | |
| totalSum += arr[i][j]; | |
| } | |
| } | |
| for (int i = 0; i < rows; i++) { | |
| for (int j = 0; j < cols; j++) { | |
| cout << arr[i][j] << "\t"; | |
| } | |
| cout << "| " << rowSums[i] << endl; | |
| } | |
| for (int j = 0; j < cols; j++) { | |
| cout << colSums[j] << "\t"; | |
| } | |
| cout << "| " << totalSum << endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment