**Question**

Given an array of unsorted array and a number, determines all pair in array in array whose sum is equivalent to the given number

For example:

```
var arr = new[] { 1, 2, 5, 6, 7, 8, 9, 2, 10,3 };
var sum = 4;
```

from provided Array *“arr”* find all Pair who sum is 4

### Answer:

Logic:

- Get the difference between array elements and given sum number
- Find the difference in reaming array to get the pairs

```
using System;
namespace FindSumPairInArray
{
class Program
{
static void Main()
{
var arr = new[] { 1, 2, 5, 6, 7, 8, 9, 2, 10 };
var sum = 4;
PairSum(arr, sum);
Console.ReadLine();
}
static void PairSum(int[] arr, int sum)
{
for (var i = 0; i < arr.Length; i++)
{
var rem = sum - arr[i];
var ss = Array.IndexOf(arr, rem, i + 1);
if (ss >= 0)
Console.WriteLine($"Sum array index {i} and {ss} values {arr[i]} + {arr[ss]} = {sum}");
}
}
}
}
```