You are viewing a single comment's thread. Return to all comments →
Why does everyone seem to keep two different totals and then subtract them at the end? Isn't it easier to just have one running total?
long total = 0; for (int i = 0; i < n; i++) { total += a[i][i]; total -= a[i][(n-1)-i]; } cout << abs(total) << endl;
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 →
Why does everyone seem to keep two different totals and then subtract them at the end? Isn't it easier to just have one running total?