in the que replace all pi ,when we get a[i]==‘p’ and a[i+1]==‘i’ now i don’t know how to shift elements so we place the the value 3.14 , so just tell me the shifting process by using variable j
Shifting of elements
if(arr[i]=='p' && arr[i+1]=='i'){
// to place 3.14 you need 4 spaces
// 2 are already present(p,i) 2 more you have to create
// first move till end
int j=i+2;// ith and i+1 th are p and i
while(arr[j]!='\0'){
j++;
}
// now go backward till i+2 and shift all charcter one by one
j+=2;
arr[j]='\0';
j--;
while(j!=i+2){
arr[j]=arr[j-2];
j--;
}
arr[i]='3';
arr[i+1]='.';
arr[i+2]='1';
arr[i+3]='4';
Replacepi(arr,i+4);
}
i hope this helps
if yes hit a like and don’t forgot to mark doubt as resolved
if you have more doubts regarding this feel free to ask
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.