#include<bits/stdc++.h>
using namespace std;
void ans(string a,string b,int i,int j){
if(i==a.length()){
cout<<b<<endl;
return;
}
b[j]=a[i];
ans(a,b,i+1,j+1);
ans(a,b,i+1,j);
}
int main(){
string a,b;
cin>>a;
ans(a,b,0,0);
return 0;
}
How i can do it using string . please check the error
hello @vvvipul007 the way of doing this queston by string is in the code in the link https://ide.codingblocks.com/s/327876.
here i have some changes in your code and now it is perfect .
i hope i have cleared your doubt .
please mark this as resolved if you feel that your doubt is resolved .
if you have any query please respond here .
Happy Learning !!
sorry but i am unable to understand how the code will work
Here I did minimal changes in your code ,only removed jth index https://ide.codingblocks.com/s/328098
This is because b[j] will not exist and can give segmentation error
to add a char to string u only have to do string+char
So I used this instead of using j
I believe u can understand the rest ,in case u don’t feel free to ask about it.