Thread: five digit number with different digits

  1. #1
    Registered User khdani's Avatar
    Join Date
    Oct 2007
    Posts
    42

    five digit number with different digits

    hello,
    how can i find the amount of five digit numbers with different digits
    without using arrays, nor strings.
    i know one way is to separate the number into digits and make about 10 if's ,
    is there a better way ?

  2. #2
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by khdani View Post
    hello,
    how can i find the amount of five digit numbers with different digits
    without using arrays, nor strings.
    i know one way is to separate the number into digits and make about 10 if's ,
    is there a better way ?
    what do u mean by amount of five digit number. give an example.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  3. #3
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    It's not much clear what you are after.
    From what I can infer, you want to parse each digit of a number separately.
    This can be done(for decimal number system) by some division and modulo logic with 10.
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    So, you want the number of permutations of 10 items (digits) taken 5 at a time? If you count a high order zero digit as a possibility, then:
    P(n,r) = n! / (n-r)!
    P(10,5) = ?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Registered User Sharke's Avatar
    Join Date
    Jun 2008
    Location
    NYC
    Posts
    303
    Code:
    for (i = 10000; i < 100000; i++)
        printf("%d\n", i);

  6. #6
    Registered User khdani's Avatar
    Join Date
    Oct 2007
    Posts
    42
    what i want is
    how many five digit numbers with all different digits exists?
    but without using strings, nor arrays...
    the most simple way is parse each number into five variables, and check for equality every pair...
    is there a better way to do it ?

  7. #7
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I think he means where each digit of the number is different.
    Ex. 12345, 12346, 12347, 23456, 23457...

    Question: Does a leading 0 count as a 5-digit number?
    Ex. 01234, 06789...
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What is your goal? To list every single number that fits the criteria, or to simply test a given number to see if that fits? That will determine how hard this task is. Start with the latter. Get a function that will return true or false for you, letting you know if a given number fits. Then if you need the former, use that function in a loop.


    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    Registered User khdani's Avatar
    Join Date
    Oct 2007
    Posts
    42
    I think he means where each digit of the number is different.
    Ex. 12345, 12346, 12347, 23456, 23457...
    exactly

    Question: Does a leading 0 count as a 5-digit number?
    Ex. 01234, 06789...
    no, five digit numbers in range from 10000 till 99999

    What is your goal? To list every single number that fits the criteria, or to simply test a given number to see if that fits? That will determine how hard this task is. Start with the latter. Get a function that will return true or false for you, letting you know if a given number fits. Then if you need the former, use that function in a loop.
    to list every single number that fits this criteria.
    functions, strings, arrays, pointers are not allowed

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well get to work. I don't see you doing anything with all of our suggestions.


    Quzah.
    Hope is the first step on the road to disappointment.

  11. #11
    Registered User khdani's Avatar
    Join Date
    Oct 2007
    Posts
    42
    i know one way is to separate the number into digits and make about 10 if's ,
    is there a better way ?

    yes i did

  12. #12
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    Quote Originally Posted by khdani View Post
    yes i did
    I am pretty sure there would always be a better way to solve any problem no matter what it is.
    So unless you post your code, i am afraid the chances of getting an useful reply are bleak.

    Edit:
    One inefficient way that i can think of is to use brute force to try all the combinations using five loops and
    filter out the unwanted numbers using one or more ifs. Of course, some better solutions than
    this are possible.
    Last edited by stevesmithx; 05-03-2009 at 11:43 AM.
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. To get the sum of digits of a five digit number
    By hum_tum2005007 in forum C Programming
    Replies: 8
    Last Post: 06-15-2008, 04:39 PM
  2. smallest digit of a number
    By lakestar in forum C Programming
    Replies: 1
    Last Post: 11-11-2007, 08:57 PM
  3. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 12:56 PM
  4. Number of digits?
    By falador in forum C Programming
    Replies: 2
    Last Post: 05-13-2004, 03:52 AM
  5. Extracting individual digits from a short
    By G'n'R in forum C Programming
    Replies: 9
    Last Post: 08-30-2001, 10:30 AM