Recursive number of digits P51222


Statement
 

pdf   zip   main.cc   main.c   main.java   main.py

thehtml

Write a recursive function that returns the number of digits of n.

Interface

C++
int number_of_digits(int n);
C
int number_of_digits(int n);
Java
public static int numberOfDigits(int n);
Python
number_of_digits(n) # returns int
 
number_of_digits(n: int) -> int

Precondition

We have n ≥ 0.

Observation You only need to submit the required procedure; your main program will be ignored.

Public test cases
  • Input/Output

    number_of_digits(7) → 1
    number_of_digits(4321) → 4
    number_of_digits(0) → 1
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C C++ Java Python
    User solutions
    C C++ Java Python Rust