View difference between Paste ID: HBsTZh30 and 9UpQem8u
SHOW: | | - or go back to the newest paste.
1
#include <iostream>
2
using namespace std;
3
4
int main(int argc, char* argv[]) {
5-
    int matrix[3][3];
5+
	int n, m;
6-
    int X = sizeof(matrix)/sizeof(*matrix);
6+
	cout << "n: ";
7-
    int Y = sizeof(*matrix)/sizeof(*matrix[0]);
7+
	cin >> n;
8
	cout << "m: ";
9
	cin >> m;
10
11
    int matrix[n][m];
12
    int X = sizeof(matrix)/sizeof(matrix[0]);
13
    int Y = sizeof(matrix[0])/sizeof(matrix[0][0]);
14
 
15
    for (int j = 0; j < X; ++j) {
16
        for (int i = 0; i < Y; ++i) {
17
    cout << "Enter the " << j << " - " << i << " element of the matrix: ";
18
    cin >> matrix[j][i];
19
        }
20
    }
21
    cout << endl;
22
    
23
    int results[sizeof(matrix) / sizeof(*matrix)];
24
    int index = 0;
25
 
26
    for (int j = 0; j < Y; ++j) {
27
        int temp = 0;
28
        for (int i = 0; i < X; ++i)
29
            if (matrix[i][j] >= 0) {
30
	    temp += matrix[i][j];
31
            }
32
	else {
33
	    temp += 0;
34
	}
35
 
36
        if (temp > 0) {
37
	results[index] = temp;
38
        } else {
39
	results[index] = 0;
40
        }
41
        index = index + 1;
42
    }
43
    
44
    for (int i = 0; i < (sizeof(results)/sizeof(*results)); ++i) {
45
	cout << results[i] << ' ';
46
    }
47
    
48
    cout << endl;
49
 
50
    system("PAUSE");
51
    return 0;
52
}