Skip to content

Commit 3f52128

Browse files
Merge pull request #45 from Yash636261/main
Create recursive.cpp
2 parents 7d922ea + 7fc594f commit 3f52128

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

CPP/array-2d/recursive.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include<iostream>
2+
using namespace std;
3+
bool exp(int arr[],int n,int target,int count=0)
4+
{
5+
;
6+
if(count==3&&target==0)
7+
return true;
8+
if(count==3||n==0||target<0)
9+
return false;
10+
return exp(arr, n - 1, target - arr[n - 1], count + 1) ||
11+
exp(arr, n - 1, target, count);
12+
}
13+
int main(){
14+
int arr[]={ 2, 7, 4, 0, 9, 5, 1, 3 };
15+
int target = 6;
16+
int n=sizeof(arr)/sizeof(arr[0]);
17+
exp(arr,n,target,0)?cout<<"triplets exist":
18+
cout<<"tripletes doesn't exists";
19+
return 0;
20+
}

0 commit comments

Comments
 (0)