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

Write the program to arrange the n queen(queen of chessboard) in n*n matrix such that they can not ATTACK TO eachother.

Write a program to reverse the string. input = google output = elgoole */

Write a program to add natural numbers up to 20 by using for loop in c++ language.