What is the difference?

What is the difference between two codes?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
              int x = 1;
            int y = 1;
            int z = 1;
            for (int i = 0; i < rows; i++){
                for (int j = 0; j < cols + rows - 1; j++){
                    if ( i == j ){
                        x = x*d[i][j];
                }
                if (i+1 == j){
                y = y*d[i][j];
                }
                if(i+2==j){
                    z=z*d[i][j];
                }}}
cout << x + y + z;



1
2
3
4
5
6
7
8
9
10
            int x = 1;
            int x1 = 0;
         for (int g = 0; g < rows -1; g++){
            for (int i = 0; i < rows; i++){
                for (int j = 0; j < cols + rows - 1; j++){
                    if ( i + g== j ){
                        x = x*d[i][j];
                }
                }}x1 = x1 + x;}
cout << x1;


Hint:
Both rows and cols == 3;

How to equalize the 2nd one to 1st one?
Last edited on
Indentation, please.

Brain hurts. Guess what this does:
1
2
3
4
5
6
7
8
9
10
11
12
13
int x = 1;
int y = 1;
int z = 1;
for ( int i = 0; i < rows-2; ++i ) {
  x *= d[i][i];
  y *= d[i][i+1];
  z *= d[i][i+2];
}
x *= d[rows-2][rows-2];
y *= d[rows-2][rows-1];
x *= d[rows-1][rows-1];

cout << x + y + z;
Solved
Topic archived. No new replies allowed.