Subsequence using recursion


it is giving wrong output.Pl tell the mistake

Hello,

Please, read the question properly as you have to create two functions:

  1. First that prints all the substrings with return type void.

  2. Second which returns the count of substrings.

Now, Coming back to your problem:

  1. How are you so sure that the length of the input string is not more than 100? Correct it.

  2. As, per the requirement of the question:
    …Observe the sample output: You have to print substrigs in an order, starting from last index.

Modify your code as suggested above.
You can take help of this post.
Keep in mind you have to print β€œβ€ also.

Hope, this would help.
If you still face problem, let me know.

sir I was not asking about the question.I have just written a simple subsequence code but it is not giving correct output.Pl tell the mistake in the code.

Okay, No Problem.

When you say subsequence, then it includes all sub strings of length in range 1 to size of main sequence(say n).

Coming back to your code,
It is printing only the strings of length n.
As you can see the first condition of the loop says,
if(inp[i]==’\0’){
out[j]==’\0’;
cout<<out<<" ";
return;
}

and β€˜\0’ will comes after all n characters of the string.
Hence, it will satisfy only for subsequence of length n.

Click here to better understand the logic.

Hope, this would help.