Skip to content

Instantly share code, notes, and snippets.

@vlaleli
Created February 13, 2025 14:37
Show Gist options
  • Select an option

  • Save vlaleli/5cfbcedfc65ef0e0df44841afbe1a884 to your computer and use it in GitHub Desktop.

Select an option

Save vlaleli/5cfbcedfc65ef0e0df44841afbe1a884 to your computer and use it in GitHub Desktop.
#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