Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7068759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:21:48+00:00 2026-05-28T05:21:48+00:00

I need to write recursive function Repl takes as input an expression in e

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:21:49+00:00Added an answer on May 28, 2026 at 5:21 am

    It is not clear why you would want a recursive solution for this problem, but the solution is relatively straightforward. Here is pseudocode:

    string replace(string s, bool seenDigit) {
        if (s == "") {
            // The string is empty : we are done
            return "";
        }
        if (s[0] is digit) {
            if (seenDigit) {
                // This is a second, third, etc. digit in a multi-digit chain
                // It has been replaced with "1" already, so we cut it out
                return replace(s.substring(1), true);
            } else {
                // This is the first digit in a chain of one or more digits
                // Replace it with "1", and tell the next level that we've
                // done the replacement already
                return "1"+replace(s.substring(1), true);
            }
        } else {
            // Non-digits do not get replaced
            return s[0] + replace(s.substring(1), false);
        }
    }
    

    s[0] means the first character; string+string denotes concatenation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a non-recursive version of the function sum-squares and Use a
I need to write a recursive function that can add two numbers (x, y),
What I am trying is write recursive function which returns the least common divisor
I need to write a recursive function that utilizes just two string methods, .empty?
I need to write a function that is the recursive version of summing up
Write a recursive function search(l,key) that returns a boolean: True if key is in
I need to write a function which will detect if the input contains at
i need to write a function, which takes positive integers list. If list begins
I have been at this all day, trying to write a recursive function in
I need to write a function which iterates through alphabet (a-z) like this: (here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.