I need help please, how can I write a program to count the number of digits of an integer the user entered ?

7 visualizzazioni (ultimi 30 giorni)
For example, I asked the user to input a number and he entered 5984, how can I write a program to count how many digits it has (which is 4)? Thank you.

Risposta accettata

madhan ravi
madhan ravi il 23 Set 2020
Modificato: madhan ravi il 23 Set 2020
strlength(abs(5984) + "")

Più risposte (1)

Ameer Hamza
Ameer Hamza il 23 Set 2020
An alternative
n = floor(log10(5984)+1)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by