I would like to know how I can find the length of an integer in C. For instance: 1 => 1 ;25 => 2;1251 => 4;0 => 1 and so on. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I would like to know how I can find the length of an integer in C. For instance: 1 => 1 ;25 => 2;1251 => 4;0 => 1 and so on.

Like is there any command for int like strlength for char ,

8th Sep 2020, 3:22 AM
s.ruthvik
s.ruthvik - avatar
4 Answers
+ 3
Although there is not by inbuilt function to do so but you can either use Robert Atkins 's method or just do some maths and use ( log10() ) for that, like this👇 int len = ceil(log10(num)); ⚠️ This will not work for some edge cases, just put a *if-else* for them (I leave them to you )
8th Sep 2020, 3:44 AM
Arsenic
Arsenic - avatar
+ 2
Robert Atkins there are a ton of uses of log in maths. Just have a look at this👇 for some of the general applications. https://math.stackexchange.com/questions/16342/what-is-the-point-of-logarithms-how-are-they-used
8th Sep 2020, 5:03 AM
Arsenic
Arsenic - avatar
+ 1
Arsenic what is the purpose of logarithms? I know in big O log2n is a decent runtime, but as far actual mathmatically application i only took pre calc and wasnt really focused.
8th Sep 2020, 4:06 AM
Robert Atkins
Robert Atkins - avatar
0
Counter = 0 While number / 10 >= 1 Number /= 10 Counter++ Its somewhere along those lines, if you provide your own attempt i would be more than happy to help you out further, ill put in as much effort to help you as you put in to help yourself.
8th Sep 2020, 3:28 AM
Robert Atkins
Robert Atkins - avatar