#include <stdio.h>
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>  /// //sorted  sequense  O(n)  what we have 2 do
for unsorted xcept sorting

int main()
{

    int a[]={1,2,3,4,5};
    int x=5;
    int left=0;
    int right=5;
    int sum=0;
    while ( sum !=x && (left < right) )
    {
          sum=a[left]+a[right];
            if(sum>x)
            right--;
            else if(sum<x)
            left++;
            else
            break;
    }

    cout<<"LEFT :"<<a[left]<<"\t RIGHT:"<<a[right]<<endl;
    cout<<"whose sum is"<<sum;

    getch();

}

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to