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 7609975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:18:26+00:00 2026-05-31T01:18:26+00:00

How can I write a function that takes a string denoting a natural number

  • 0

How can I write a function that takes a string denoting a natural number (>0) such as “100100000000” or “1234567890123456788912345678912345678901234567890” and returns a string denoting the input number decreased by 1? I cannot convert this string to an integer because it could overflow.

I am open to implementing this function in any popular language. I personally know c, C++, Java, javascript, python, and php.

  • 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-31T01:18:27+00:00Added an answer on May 31, 2026 at 1:18 am
    k=len(x)-1
    
    while(True):
        if x[k]!='0':
            x[k]-=1
            break
        else:
            x[k]='9'
            k--
    

    I am leaving boundary conditions for you to work out.

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

Sidebar

Related Questions

How can I write a function in Haskell, that takes an input string in
I am trying to write a function that as input takes a string containing
How can I write a function that accepts a variable number of arguments? Is
How do I write a function that can accept unlimited number of parameters? What
i wrote a function that takes a string as input. function ajaxLoad(targetBox, loadUrl) {
I should write an app that takes string input and computes the hash value
I'm looking for the best way to write a function that takes a string
I'm trying to write a command in LaTeX that takes a string such as
I want to write a function that accepts a parameter which can be either
I need to write a delegate function that can 'wrap' some while/try/catch code around

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.