1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Count the length on a number

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

  1. kabirk007

    kabirk007 New Member

    Joined:
    Dec 2, 2008
    Messages:
    5
    Likes Received:
    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 retirement

    back from retirement New Member

    Joined:
    Nov 9, 2008
    Messages:
    72
    Likes Received:
    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??
    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....
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    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
     

Share This Page