#include
using namespace std;
int count=0;
void subsequences(charin,charout,int i,int j)
{
if(in[i]==’\0’)
{
out[j]=’\0’;
cout<<out<<" ";
count++;
return;
}
out[j]=in[i];
subsequences(in,out,i+1,j+1);
subsequences(in,out,i+1,j);
}
int main() {
char in[100];
cin>>in;
char out[100];
subsequences(in,out,0,0);
cout<<endl;
cout<<count;
return 0;
}
what is wrong in my code?
Recursion subsequences
Hi @AjayRRJ
You are facing error because you have used wrong spelling of iostream. Even after you will get your answer as for input abcd :
abcd abc abd ab acd ac ad a bcd bc bd b cd c d
16
but the correct answer should be
d c cd b bd bc bcd a ad ac acd ab abd abc abcd
16
So for this instead of printing the out you can push out in stack and at the end print all the strings in stack.
Here is your corrected code :