Count of character pairs at same distance as in English alphabets | A Simple C # program to find pairs with distance equal to English alphabet distance ; Method to count pairs ; Increment count if characters are at same distance ; Driver method
using System ; class Test { static int countPairs ( string str ) { int result = 0 ; int n = str . Length ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( Math . Abs ( str [ i ] - str [ j ] ) == Math . Abs ( i - j ) ) result ++ ; return result ; } public static void Main ( ) { string str = " geeksforgeeks " ; Console . WriteLine ( countPairs ( str ) ) ; } }