Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Count the length on a number (http://www.go4expert.com/forums/count-length-t15410/)

 kabirk007 5Dec2008 12:40

Count the length on a number

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

 back from retirement 5Dec2008 12:47

Re: Count the length on a number

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??

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....

 shabbir 5Dec2008 13:15

Re: Count the length on a number

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

 All times are GMT +5.5. The time now is 09:29.