Given an array A [ ] and a number x , check for pair in A [ ] with sum as x | C # implementation using Hashing ; function to check for the given sum in the array ; checking for condition ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static void printpairs ( int [ ] arr , int sum ) { HashSet < int > s = new HashSet < int > ( ) ; for ( int i = 0 ; i < arr . Length ; ++ i ) { int temp = sum - arr [ i ] ; if ( s . Contains ( temp ) ) { Console . Write ( " Pair ▁ with ▁ given ▁ sum ▁ " + sum + " ▁ is ▁ ( " + arr [ i ] + " , ▁ " + temp + " ) " ) ; } s . Add ( arr [ i ] ) ; } } static void Main ( ) { int [ ] A = new int [ ] { 1 , 4 , 45 , 6 , 10 , 8 } ; int n = 16 ; printpairs ( A , n ) ; } }