#include<iostream.h>
#include<conio.h>
int
array[]={10,20,30,40,50,60,70,80,90};
int n=9;
int check(int
k,int val)
{
int i=0,j=n-1;
static int flag;
while(i<j)
{
if(i==k)
{
i++;
continue;
}
if(j==k)
{
j--;
continue;
}
if(array[i]+array[j]==val)
{
cout<<"\n"<<array[i]<<"
+ "<<array[j]<<" + "<<array[k]<<" =
"<<val+array[k];
flag++;
i++;
j--;
}
else if(array[i]+array[j]>val)
j--;
else
i++;
}
return flag;
}
void main()
{
clrscr();
int val,flag;
cout<<"Enter the value ";
cin>>val;
cout<<" \n\n";
for(int i=0;i<n;i++)
flag=check(i,val-array[i]);
if(flag==0)
cout<<"\n No such
elements ";
getch();
}
No comments:
Post a Comment