Is My Code Wrong Here?. Check This Code!

I created this code & it is producing the right output!. Can I use this instead of Prateek Bhaiya’s code?

#include

using namespace std;

int main()
{
char ch[20];
cin.getline(ch,20);
int j=0,i=j+1;
while(ch[j]!=’\0’){
if(ch[j]==ch[i])
i++;
else{
j++;
ch[j]=ch[i];
}
}
cout<<ch;

return 0;

}

yes, this code is perfectly fine as long as the input is at max 20 characters long. you can take char array of larger size if input is larger, everything else is correct.

thanks

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.