Ask Question
10 January, 10:41

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

+1
Answers (1)
  1. 10 January, 13:45
    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 you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers