Simple Logic storing the value at the index of the array and then it became lot simple...
#include<iostream>
using namespace std;
void findAllNdup(int arr[], int count[], int n, int s)
{
for( int i =0; i< n; i++)
{
count[arr[ i]]++;
}
for( int j= 0; j< n; j++)
{
if( count[arr[ j]] != 0 && count[s- arr[ j]] !=0)
{
cout<<"("<< arr[ j]<<","<< s- arr[j]<<")"<< endl;
count[s- arr[ j]]=0;
}
}
}
int main()
{
int arr[] ={2,1,3,6,7,5,3,5,8,4,9,1};
int count[10]={0};
int sum =10;
int size = sizeof(arr)/sizeof(arr[0]);
findAllNdup(arr, count, size, sum);
return 0;
}
Output
(2,8)
(1,9)
(3,7)
(6,4)
(5,5)