# Count the length on a number

Discussion in 'C' started by kabirk007, Dec 5, 2008.

1. ### kabirk007New Member

Joined:
Dec 2, 2008
Messages:
5
0
Trophy Points:
0
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

2. ### back from retirementNew Member

Joined:
Nov 9, 2008
Messages:
72
1
Trophy Points:
0
Occupation:
Student, UG 1st Yr., Jadavpur University
Location:
Uttarpara, West Bengal, India
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....

Joined:
Jul 12, 2004
Messages:
15,296
366
Trophy Points:
83
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