Recursive program to replace all occurrences of pi with 3.14 in a given string | C # program for above approach ; A simple recursive approach to replace all pi in a given function with "3.14" . Firstly function is declared we don 't  need any helper function one  function is enough ; Base case if s is empty or length of s is 1 return the s ; If the 0 th and 1 st element of s are p and i we have to handle them for rest we have to call recursion it will give the result ; Smalloutput is a variable used to store recursion result ; And we have to add the recursion result with the first part we handled and return the answer ; If not then we have to call recursion from 1 st to all elements then add recursion result to 1 st element and return it ; Driver Code ; Function call
using System ; using System . Collections ; using System . Collections . Generic ; using System . Linq ; class GFG { static string replacePi ( string s ) { if ( s . Length == 0 s . Length == 1 ) return s ; if ( s [ 0 ] == ' p ' && s [ 1 ] == ' i ' ) { string smallOutput = replacePi ( s . Substring ( 2 ) ) ; return "3.14" + smallOutput ; } else { string smallOutput = replacePi ( s . Substring ( 1 ) ) ; return s [ 0 ] + smallOutput ; } } public static void Main ( string [ ] args ) { string s = " pipppiiipi " ; string result = replacePi ( s ) ; Console . Write ( result ) ; } }