#include
using namespace std;
void generate_strings(charinp,charout,int i,int j,int& ctr)
{
if(inp[i]==’\0’)
{ ctr++;
out[j]=’\0’;
cout<<out<<" ";
return;
}
out[j]=inp[i];
generate_strings(inp,out,i+1,j+1,ctr);
generate_strings(inp,out,i+1,j,ctr);
}
int main() {
char inp[10];
char out[10];
cin>>inp;
int ctr=0;
generate_strings(inp,out,0,0,ctr);
cout<<endl;
cout<<ctr;
return 0;
}
What is wrong with this code
hello @Kunalgoyal
your code is correct but it is not printing in required order.
to print in required order
order these three lines
as
generate_strings(inp,out,i+1,j,ctr);
out[j]=inp[i];
generate_strings(inp,out,i+1,j+1,ctr);
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.