You are viewing a single comment's thread. Return to all comments →
Really nice one.
You can actually move up the k -= 1 into the outer loop next to the i++ as:
int sum1=0,sum2=0; for(int i=0, k=size-1; i< size; i++, k--){ for(int j=0; j< size; j++){ cin >> matrix[i][j]; if(i==j) sum1 += matrix[i][j]; } sum2 += matrix[i][k]; } cout << abs(sum1-sum2);
Seems like cookies are disabled on this browser, please enable them to open this website
Diagonal Difference
You are viewing a single comment's thread. Return to all comments →
Really nice one.
You can actually move up the k -= 1 into the outer loop next to the i++ as: