How To Count Digits Between any numbers[Urgent]

Discussion in 'Programming' started by 123funda, Feb 21, 2010.

  1. #1
    Hi Dps
    I am automating an statistic forumala,
    i am an BSCS student i want a help
    that suppose i have integers from 1 to 10 or 2 to 5
    b/w 2 to 5 there are there are 5 digits ie 2,3,4,5
    how i can count them in C only with C,,, Which function i have to use and what function i have to use to add whole column in C
    Thanks In Advance
     
    123funda, Feb 21, 2010 IP
  2. Amator

    Amator Well-Known Member

    Messages:
    1,424
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #2
    2 to 5 -> 2,3,4,5 -> 4 ?
    Or do you mean something else ?
    Anyway, try to do your homework yourself.
     
    Amator, Feb 21, 2010 IP
  3. 123funda

    123funda Member

    Messages:
    462
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #3
    any way it is 4 digits i want to count them by C it is not my home work it is i am practicing
     
    123funda, Feb 21, 2010 IP
  4. Amator

    Amator Well-Known Member

    Messages:
    1,424
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #4
    sorry but if you can not solve this one by yourself you will never learn I think.
     
    Amator, Feb 21, 2010 IP
  5. ceku

    ceku Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Here's the logic.
    Do the increment from the small number to the big number

    for (i=small number,small_number -> big number){
    i++;
    if (i<big number) count++;
    }
     
    ceku, Feb 21, 2010 IP
  6. Amator

    Amator Well-Known Member

    Messages:
    1,424
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #6
    the formula is much easier, you just need 1 small formula.

    bignumber - smallnumber + 1
     
    Amator, Feb 21, 2010 IP
  7. ceku

    ceku Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    that would be much easier but not reliable. what if the number is negative?
     
    ceku, Feb 21, 2010 IP
  8. Amator

    Amator Well-Known Member

    Messages:
    1,424
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #8
    you're right but the answer is still simplier

    bignumber - (smallnumber - 1)
     
    Last edited: Feb 21, 2010
    Amator, Feb 21, 2010 IP
  9. NeoCambell

    NeoCambell Peon

    Messages:
    456
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #9
    can't you get it simply by (5-2)+1 ?

    So in general (big number - small number) + 1
     
    NeoCambell, Feb 21, 2010 IP
  10. Amator

    Amator Well-Known Member

    Messages:
    1,424
    Likes Received:
    55
    Best Answers:
    0
    Trophy Points:
    165
    #10
    yes, is also right
     
    Last edited: Feb 21, 2010
    Amator, Feb 21, 2010 IP
  11. NeoCambell

    NeoCambell Peon

    Messages:
    456
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Since you are going to use C for this, you can easily get this done without considering the numbers as below. abs is used to get the absolute value of the difference.

    #include <math.h>

    abs(number_1 - number_2) + 1
     
    NeoCambell, Feb 21, 2010 IP