my code i am not getting out print
#include
using namespace std;
void generate(char out[],int n,int i,int open,int close){
if(i=2*n){
out[i]=NULL;
for(int j=0;out[j]!=NULL;j++){
cout<<out[j]<<endl;}
return;
}
if(open<n){
out[i]=’(’;
generate(out,n,i+1,open+1,close);
}if(open>close){
out[i]=’)’;
generate(out,n,i+1,open,close+1);
}
return;
}
int main() {
char out[100];
int n;
cin>>n;
generate(out,n,0,0,0);
return 0;
}
No output print
Hello @toshitvarshney11,
- No output is because of the base case.
- Also, the order of inserting bracket is wrong.
- You are printing the output incorrectly.
Corrected code:
Hope, this will help.
Give a like if you are satisfied.