# Find all pair of Array of Integers whose sum is equal to a given number in C#

Our task is to find all the possible pairs (no duplication) of integers whose sum is given. See below examples:

Array : [2, 4, 3, 5, 6, -2, 4, 7, 8, 9]
Given sum : 7
pairs whose sum is equal to value : 7
(2, 5) , (4, 3) , (3, 4) , (-2, 9)

Array : [0, 14, 0, 4, 7, 8, 3, 5, 7]
Sum : 11
pairs whose sum equals: 11
(7, 4) , (3, 8) , (7, 4)

Array : [10, 9, 5, 9, 0, 10, 2, 10, 1, 9]
Sum : 12
pairs whose sum equals 12
(2, 10)

There are two ways of doing this,

Method 1: Brute Force approach – use two nested loops and make a pair and compare sum of them with given number. Its time complexity would be O(n^2).

Method 2: In this method we loop over the array only once. For each item of array, subtract this item from given number and if array item doesn’t exist in our list then add it otherwise print this item and subtraction of array item and given number. Its time complexity would be O(n) as we loop over only once and comparison are also less.

```        static void Main(string[] args)
{
int[] arr = { 2, 4, 3, 5, 6, -2, 4, 7, 8, 9 };
int n = 7;
PrintPairs(arr, n);
}

private static void PrintPairs(int[] arr, int n)
{
List<int> arrayItemList = new List<int>();
foreach (var item in arr)
{
int remainingvalue = n - item;
if (arrayItemList.Contains(remainingvalue))
{
Console.WriteLine(\$"({ item},{remainingvalue})");
}
else
{