You are viewing a single comment's thread. Return to all comments →
I did about the same, but using a single for loop and a single sum variable:
#include <stdio.h> #include <stdlib.h> int main(void) { int sz; scanf("%d", &sz); int sum = 0; for (int i = 0; i < sz*sz; i++) { int x; scanf("%d", &x); if (!(i % (sz+1))) sum += x; if (i > sz-2 && i < sz*sz-1 && !(i % (sz-1))) sum -= x; } printf("%d\n", abs(sum)); }
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 →
I did about the same, but using a single for loop and a single sum variable: