Ask Question
26 November, 08:13

Write a function digits () that accepts a non-negative integer argument n and returns the number of digits in it's decimal representation. For credit, you should implement this using a loop and repeated integer division; you should not use math. log (), math. log10 (), or conversion to string

+2
Answers (1)
  1. 26 November, 08:30
    0
    Let do this in python. We will utilize the while loop and keep on dividing by 10 until that number is less than 10. Along the loop we will count the number of looping process. Once the loop ends, we can output that as answer.

    def digits (n):

    n_digit = 1

    while n > = 10:

    n_digit + = 1

    n / = 10

    return n_digit
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a function digits () that accepts a non-negative integer argument n and returns the number of digits in it's decimal representation. ...” in 📗 Engineering if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers