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

  • SEARCH
  • Home
  • 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 7493783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:10:43+00:00 2026-05-29T17:10:43+00:00

On a whim, I’ve decided to go back and seek certification, starting with 98-361,

  • 0

On a whim, I’ve decided to go back and seek certification, starting with 98-361, Fundamentals of Software Development. (I’m doing this more for myself than anything else. I want to fill in gaps in my knowledge.)

In the very early course of the book, they present this interesting scenario in the Proficient Assessment section:

You are developing a library of utility functions for your
application. You need to write a method that takes an integer and
counts the number of significant digits in it. You need to create a recursive program
to solve this problem. How would you write such a
program?

I find myself gaping at this scenario in befuddlement. If I understand “significant digits” correctly, there’s no need whatsoever for a function that counts an integer’s significant digits to be recursive. And, any architect who insisted that it be recursive should have his head examined.

Or am I not getting it? Did I completely miss something here? From what I understand, the significant digits are the digits of a number, starting from the left, and proceeding right, excluding any leading zeroes.

Under what conditions would this need to be recursive? (The whole point of this exercise for me is to learn new things. Someone throw me a bone.)

EDIT: I don’t want an answer to the problem question. I can figure that out on my own. It just seems to me that this “problem” could be solved far more easily with a simple foreach loop over the characters in a string.

Final Edit

Given the sage advice of the awesome posters below, this was the simple solution I came up with to solve the problem. (Despite what misgivings I may have.)

using System;

class Program
{
    static void Main(string[] args)
    {

        var values = new[] { 5, 15, 150, 250, 2500, 25051, 255500005, -10, -1005 };
        foreach (var value in values)
        {
            Console.WriteLine("Signficiant digits for {0} is {1}.", value, SignificantDigits(value));
        }
    }

    public static int SignificantDigits(int n)
    {
        if (n == 0)
        {
            return 0;
        }

        return 1 + SignificantDigits((int)(n / 10));
    }
}
  • 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-29T17:10:55+00:00Added an answer on May 29, 2026 at 5:10 pm

    There’s no need for such an algorithm to be recursive. But the intent here is not to write real-world code, it’s to ensure you understand recursion.

    Since you stated you weren’t after code, I’ll be careful here, but I need to provide something to compare the complexity of the solutions, so I’ll use pseudo-code. A recursive solution may be something like:

    def sigDigits (n):
        # Handle negative numbers.
    
        if n < 0:
            return sigDigits (-n)
    
        # 0..9 is one significant digit.
    
        if n < 10:
            return 1
    
        # Otherwise it's one plus the count in n/10 (truncated).
    
        return 1 + sigDigits (n / 10)
    

    And you’re right, it equally doable as iteration.

    def sigDigits (n):
        # Handle negative numbers.
    
        if n < 0:
            n = -n
    
        # All numbers have at least one significant digit.
    
        digits = 1
    
        # Then we add one and divide by ten (truncated), until we get low enough.
    
        while n > 9:
            n = n / 10
            digits = digits + 1
    
        return digits
    

    There are some (usually of a mathematical bent, and including myself) that consider recursive algorithms much more elegant where they’re suitable (such as where the “solution search space” reduces very quickly so as to not blow out your stack).

    I question the suitability in this particular case since the iterative solution is not too complex, but the questioner had to provide some problem and this one is relatively easy to solve.

    And, as per your edit:

    … could be solved far more easily with a simple foreach loop over the characters in a string

    You don’t have a string, you have an integer. I don’t doubt that you could turn that into a string and then count characters but that seems a roundabout way of doing it.

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

Sidebar

Related Questions

UDPATE On a whim, I decided to upload the 4 fonts files to an
I know it sounds crazy, but I do have a reason for doing this.
Yeah, so this one through me or a loop for a while until I
On a whim, I tried to define the main function as a template function
I never thought this would be a problem with Node.js and Express, but on
We have the following shared component: public class OurServiceBase : System.ServiceProcess.ServiceBase This class has
On a whim, in order to learn PowerShell, which I know I'm woefully behind
This is how I understand I can implement the singleton pattern in C#: public
Summary of the question: I came to realise as I wrote this out that
I'm wondering if it's possible to toggle back and forth between fullscreen mode and

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.