my code
#include
using namespace std;
void generate(char out[],int n,int i,int open,int close){
if(i==2*n){
out[i]=NULL;
cout<<out<<endl;
return;
}
if(open<n){
out[i]=’(’;
generate(out,n,i+1,open+1,close);
}
if(close<open){
out[i]=’)’;
generate(out,n,i+1,open,close+1);
}
}
int main(){
int n;
cin>>n;
char out[100];
generate(out,n,0,0,0);
return 0;
}
Error in all cases but compilation and custom input show right ans
take a string to append it
since it is not known how many balanced parenthesis will be generated
What is ur doubt. Your doubt has already been replied.