Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main(int argc, char* argv[]) {
- int n, m;
- cout << "n: ";
- cin >> n;
- cout << "m: ";
- cin >> m;
- int matrix[n][m];
- int X = sizeof(matrix)/sizeof(matrix[0]);
- int Y = sizeof(matrix[0])/sizeof(matrix[0][0]);
- for (int j = 0; j < X; ++j) {
- for (int i = 0; i < Y; ++i) {
- cout << "Enter the " << j << " - " << i << " element of the matrix: ";
- cin >> matrix[j][i];
- }
- }
- cout << endl;
- int results[sizeof(matrix) / sizeof(*matrix)];
- int index = 0;
- for (int j = 0; j < Y; ++j) {
- int temp = 0;
- for (int i = 0; i < X; ++i)
- if (matrix[i][j] >= 0) {
- temp += matrix[i][j];
- }
- else {
- temp += 0;
- }
- if (temp > 0) {
- results[index] = temp;
- } else {
- results[index] = 0;
- }
- index = index + 1;
- }
- for (int i = 0; i < (sizeof(results)/sizeof(*results)); ++i) {
- cout << results[i] << ' ';
- }
- cout << endl;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement