fork download
  1. //CODE TO GENERATE ALL THE SUBSEQUENCES OF A
  2. #include <iostream>
  3. using namespace std;
  4. void subsequences(char in[],char out[],int i,int j)
  5. {
  6. if(in[i]=='\0')
  7. {
  8. out[j]='\0';
  9. cout<<out<<"\n";
  10. return;
  11. }
  12. //RECURSIVE CASE EITHER INCLUDE.
  13. out[j]=in[i];
  14. subsequences(in,out,i+1,j+1);
  15. //EXCLUDING PART RECURSIVE CASE.
  16. out[j]='\0';
  17. subsequences(in,out,i+1,j);
  18. }
  19. int main() {
  20. // your code goes here
  21. char a[]="abcd",b[1000];
  22. subsequences(a,b,0,0);
  23. return 0;
  24. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
abcd
abc
abd
ab
acd
ac
ad
a
bcd
bc
bd
b
cd
c
d