Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main()
- {
- const int rows{ 3 };
- const int cols{ 3 };
- int arr[rows][cols]{};
- int colSum[cols]{};
- int sum{ 0 };
- int totalSum{ 0 };
- for (int y{ 0 }; y < rows; ++y)
- {
- for (int x{ 0 }; x < cols; ++x)
- {
- arr[y][x] = rand() % 10;
- sum += arr[y][x];
- std::cout << arr[y][x] << '\t';
- colSum[x] += arr[y][x];
- }
- std::cout << sum << '\n';
- sum = 0;
- }
- std::cout << '\n';
- for (int x{ 0 }; x < cols; ++x)
- {
- std::cout << colSum[x] << '\t';
- totalSum += colSum[x];
- }
- std::cout << totalSum << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement