#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,val,i,j;
int array[]={10,20,30,40,50,60,70,80};
n=8;
cout<<" \n\nEnter the value
:";
cin>>val;
int flag=0;
i=0,j=n-1;
while(i<j)
{
if(array[i]+array[j]==val)
{
cout<<"\n"<<array[i]<<"
+ "<<array[j]<<" = "<<val;
flag=1;
i++;
j--;
}
else if(array[i]+array[j]>val)
j--;
else
i++;
}
if(flag==0)
cout<<"\nNo such
elements";
getch();
}
sort the array using quick sort in O(nlogn).
ReplyDelete