Given a matrix of size NxN. Rows and Columns are numbered from 0 to N-1. jth column of ith row contains absolute difference between i and j.
In other words, Matrix[i][j] = abs(i-j) where 0 ≤ i, j < N.
you have to find sum of this matrix
i.e.,
For example:
If the size of the matrix is 2
Matrix will be:
= 2
If the size of the matrix is 3
Matrix will be:
= 8
Implementation:
In other words, Matrix[i][j] = abs(i-j) where 0 ≤ i, j < N.
you have to find sum of this matrix
i.e.,
sum = 0
for i=0 to N-1
for j=0 to N-1
sum += Matrix[i][j]
For example:
If the size of the matrix is 2
Matrix will be:
0 1
1 0
Sum = 0 + 1 + 1 + 0= 2
If the size of the matrix is 3
Matrix will be:
0 1 2
1 0 1
2 1 0
Sum = 0 + 1 + 2 + 1 + 0 + 1 + 2 + 1 + 0= 8
Implementation: