Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int main()
- {
- const int rows = 5;
- const int cols = 9;
- int arr[rows][cols]{};
- int colSum[cols]{};
- int sum = 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'; } std::cout << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment