Sum of Manhattan distances between all pairs of points | C # Program to find sum of Manhattan distance between all the pairs of given points ; Return the sum of distance between all the pair of points . ; for each point , finding distance to rest of the point ; Driven Program
using System ; class GFG { static int distancesum ( int [ ] x , int [ ] y , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) sum += ( Math . Abs ( x [ i ] - x [ j ] ) + Math . Abs ( y [ i ] - y [ j ] ) ) ; return sum ; } public static void Main ( ) { int [ ] x = { - 1 , 1 , 3 , 2 } ; int [ ] y = { 5 , 6 , 5 , 3 } ; int n = x . Length ; Console . WriteLine ( distancesum ( x , y , n ) ) ; } }