TITLE:-
Triplet sum
PROBLEM:-
Line 1 : Integer N (Array Size)
Line 2 : Array elements (separated by space)
Line 3 : Integer x
Line 1 : Triplet 1 elements (separated by space)
Line 2 : Triplet 3 elements (separated by space)
Line 3 : and so on
7
1 2 3 4 5 6 7
12
1 4 7
1 5 6
2 3 7
2 4 6
3 4 5
SOLUTION:-
#include <iostream>
using namespace std;
#include<bits/stdc++.h>
void FindTriplet(int arr[], int n, int x)
{
sort(arr,arr+n);
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
for(int k=j+1;k<n;k++)
{
if(arr[i]+arr[j]+arr[k]==x)
{
cout<<arr[i]<<" "<<arr[j]<<" "<<arr[k]<<endl;
}
}
}
}
}
int main() {
int size;
int x;
cin>>size;
int *input=new int[1+size];
for(int i=0;i<size;i++)
cin>>input[i];
cin>>x;
FindTriplet(input,size,x);
return 0;
}
This is dummy text. It is not meant to be read. Accordingly, it is difficult to figure out when to end it. But then, this is dummy text. It is not meant to be read. Period.
If you have any doubts then please let me know... ConversionConversion EmoticonEmoticon