I need to write recursive function Repl
takes as input an expression in e in Expr and returns an expression in Expr
wherein each number is replaced by the number 1.
For example, if e is the expression
((((9 + 5) ∗ 2) ∗ (2 + (4 ∗ 6))))
then Repl(e) is the expression
((((1 + 1) ∗ 1) ∗ (1 + (1 ∗ 1))))
Can anybody help me how to go about this?
Iterative one is easy to write but how to write it recursively?
It is not clear why you would want a recursive solution for this problem, but the solution is relatively straightforward. Here is pseudocode:
s[0]means the first character;string+stringdenotes concatenation.