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 ; Length of the array ; Calculate the number of valid pairs ; Return the count of valid pairs ; Driver code
using System ; class GFG { static int getPairs ( int [ ] a ) { int n = a . Length ; int count = ( n * ( n - 1 ) ) / 2 ; return count ; } public static void Main ( ) { int [ ] a = { 2 , 4 , 3 , 1 } ; Console . Write ( getPairs ( a ) ) ; } }