+ 4
Efficient way to find length of integer in c++?
Looking for an easy and efficient meathod to find length of an integer. The integer can be negative or positive. I cannot include any libraries.
5 Respostas
+ 9
This is an algorithm which I just came up with.
Please test and see if it works for all values.
https://code.sololearn.com/cv0xQoe9xit7/?ref=app
+ 8
Do something like this
https://code.sololearn.com/c3iZdG7FcXqu/?ref=app
+ 2
Divide by 10 until the answer is < 1? I haven't completely thought this through...
edit: yeah...negatives. Glad others popped in :)
+ 2
@Little Grass
Though "-" is easily fixed, unfortunately to_string() is not in gcc (and it requires a lib).
- 2
to_string(a).size()