Count the length on a number

kabirk007's Avatar, Join Date: Dec 2008
Light Poster
i have a very simple query?

anybody can tell me, how can i find the length of the number, which was enter by user.

like:- 1234
length should be 4


thanks
0
back from retirement's Avatar, Join Date: Nov 2008
Contributor
Just as xpi0t0s always says.....how will you do it on paper???
I mean, can you do it as a lame-man, without any pc provided to you??
If you can, you can design your algorithm on your own....

Little hint, from my part, the way we express the integers (say e.g. abcde is an integer) is not the proper expression....it is obtained by summing up the proper expression....
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Are you looking for and API or just logic.

I would use the following logic

I would divide it by 10 and store it in a integer and if its greater than 10 repeat the process and increase the length of the number

As an example

1234 / 10 = 123 Length = Loop var = 1
123 / 10 = 12 Length = Loop var = 2
12 / 10 = 1 Length = Loop var = 3
1 / 10 = 0 Length = Loop var = 4