C++ code programming .

computer science

Description

#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int n,i,j,k,low,up,mid;
cout<<"Enter the number of elements(any positive integer)"<<endl;
cin>>n;
int a[n];
cout<<"Enter the elements one by one"<<endl;
for(i=0;i<n;i++)
cin>>a[i];
for(i=1;i<n;i++)
{
k=a[i];
for(j=i-1;j>=0 && k<a[j];j--)
a[j+1]=a[j];
a[j+1]=k;
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
k=(a[i]+a[j])*(-1);
low=0;
up=n-1;
while(low<=up)
{
mid=(low+up)/2;
if(k>a[mid])
low=mid+1;
else if(k<a[mid])
up=mid-1;
else
{
cout<<"YES";
exit(1);
}
}
}
}
cout<<"NO";
return 0;

Instruction Files
Lab2.cpp
806.0 Bytes

Related Questions in computer science category


Disclaimer
The ready solutions purchased from Library are already used solutions. Please do not submit them directly as it may lead to plagiarism. Once paid, the solution file download link will be sent to your provided email. Please either use them for learning purpose or re-write them in your own language. In case if you haven't get the email, do let us know via chat support.