Count of pairs ( x , y ) in an array such that x < y | C # implementation of the approach ; Function to return the number of pairs ( x , y ) such that x < y ; To store the number of valid pairs ; If a valid pair is found ; Return the count of valid pairs ; Driver code
using System ; class GFG { static int getPairs ( int [ ] a ) { int count = 0 ; for ( int i = 0 ; i < a . Length ; i ++ ) { for ( int j = 0 ; j < a . Length ; j ++ ) { if ( a [ i ] < a [ j ] ) count ++ ; } } return count ; } public static void Main ( ) { int [ ] a = { 2 , 4 , 3 , 1 } ; Console . WriteLine ( getPairs ( a ) ) ; } }