Why do you want both the pairs to be printed? I guess the problem's
originality is only in finding unique pairs summing to a particular
number, so there's no point in printing repeating pairs.
Besides, even if you want to do that, daizi's code can be altered quite
simply to print repeating pairs.
well if the index of the elements are not imp then it's fine...but if
they are then may be we will have to use some other way..
like find all the indexes from left (i) and right(j) till the sum is
equal to the required sum and then find all possible pair of the
indexes.
thnx
one more version...
int a[]={1,-5,6,7,9,9,20,25,31,45};
int i=0,j=1,n=10;
int c;
while(ij)
{
c=a[i]+a[j];
if(c26)j++;
else
if(c26)i++;
else
printf(%d %d ,a[i++],a[j]);
thanks. it works.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL