#include<bits/stdc++.h>
using namespace std;
int main()
{
int n, f = 0;
cout << "Enter Array Size :: ";
cin >> n;
int a[n];
cout << "\nEnter Array Element :: ";
for(int i=0;i<n;i++)
cin >> a[i];
cout << "\n";
sort(a, a+n);
for(int i=n-1;i>=0;i--)
{
int l = 0, r = i-1;
while(l < r)
{
if(a[i] == a[l]+a[r])
{
f = 1;
cout << a[i] << " = " << a[l] << " + " << a[r] << "\n";
}
if(a[i] > a[l] + a[r])
l++;
else
r--;
}
}
if(f == 0)
cout << "No Triplet Found." << "\n";
return 0;
}
Comments
Post a Comment