Write the program to replace pi with 3.14 in string. input = pippdfpig output = 3.14ppdf3.14g

 


#include<iostream>
using namespace std;
void removepi(string a)
   {if(a.size()==0)
        {return ;}
   
   if(a[0]=='p' && a[1]=='i')
     {cout<<"3.14";
      removepi(a.substr(2));}
      else {cout<<a[0];
       removepi(a.substr(1));}        
    }

int main()
{
    string a;
     a="pippdfpig";
    removepi(a);
    return 0;
}

Comments

Popular posts from this blog

Use of Recursion