#include <iostream> #include<cmath> #include<limits.h> #include<stdio.h> #include<algorithm> #include<stdlib.h> using namespace std; int main() { long int n=0; long int a[n]; long int value; cin>>n; for(int i=0; i<n;> { cin>>a[i]; } cin>>value; cout<<endl; int temp=0,temp2=0; float diff=0.0,diff2=0.0; for(int i=0; i<n;> { temp=a[i]; for(int j=i+1; j<n;> { if(i==0) { if(temp+a[j]==value) { temp2=a[j]; diff=temp2-temp; diff=abs(diff); cout<<"temp="<<temp<<"temp2="<<temp2<<"diff="<<diff<<endl; } } else { if(temp+a[j]==value) { temp2=a[j]; diff2=temp2-temp; diff2=abs(diff2); if(diff2<diff)> diff=diff2; cout<<"temp="<<temp<<"temp2="<<temp2<<"diff="<<diff<<endl; } } } } cout<<"diff="<<diff<<" value="<<value<<endl; int aa=(value+diff)/2; int b=(value-diff)/2; cout<<"Peter should buy books whose prices are "<<b<<" and "<<aa<<endl;</stdlib.h></algorithm></stdio.h></limits.h></cmath></iostream>
#include <stdlib.h>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)