why did we move j to end of the array ?
also i dont understand what is happening in
while(j>=i+2){
a[j+2]=a[j];
j–;
}
how are we copying from right to left i dont understand
why did we move j to end of the array ?
also i dont understand what is happening in
while(j>=i+2){
a[j+2]=a[j];
j–;
}
how are we copying from right to left i dont understand
hi @chitranshanmol07
pi occupies 2 characters
3.14 occupies 4 characters
so we have to make some extra space to accomodate this
to do that, we shift all the characters to the right side by 2 places. This shift is done most efficiently and easily when we start from the right side.
Do a dry run of this code for more clarification
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.