I have to find a diagonal difference in a matrix represented as 2d array and the function prototype is
int diagonal_diff(int x[512][512])
I
With one minor change you can have your loops only operate on the desired indices. I just changed the j loop initialization.
j
int i, j, result = 0; for (i = 0; i < 4; ++i) { for (j = i + 1; j < 4; ++j) { result += abs(array[i][j] - array[j][i]); } }