Powerset of the string

lets say this is the code to solve the substring of a char array
#include <bits/stdc++.h>
using namespace std;
void powerset(char *s){
for(int i=0;s[i]!=’\0’;i++){
for(int j=i;s[j]!=’\0’;j++){
for(int k=i;k<=j;k++){
cout<<s[k];
}
cout<<endl;
}
}
}

int main()
{
char str[100];
cin.getline(str,100);
powerset(str);

return 0;
}
input and output will be following :
abc
output:
a
ab
abc
b
bc
c

what if i want to print all elements like
a
b
c
ab
bc
ac
abc
any suggestion?

Hello @Vivek-Pandey-2129725577345937,

You have included an extra element ac which not a substring.
So, the output that you demand is:
a
b
c
ab
bc
abc

Yes, it is possible.
I am modifying your code only.

  1. I am using the first loop to keep track of the length of the substring.
    i.e. starting from 1 and then gradually increasing.

  2. The second loop is to define the starting index of the substring.

  3. The third loop is to print the substring.

Following is the modified code:

Hope, this would help.
Give a like if you are satisfied.