# five digit number with different digits

• 05-01-2009
khdani
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 ?
• 05-01-2009
BEN10
Quote:

Originally Posted by khdani
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.
• 05-01-2009
stevesmithx
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.
• 05-01-2009
hk_mp5kpdw
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) = ?
• 05-01-2009
Sharke
Code:

```for (i = 10000; i < 100000; i++)     printf("%d\n", i);```
• 05-01-2009
khdani
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 ?
• 05-01-2009
cpjust
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...
• 05-01-2009
quzah
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.
• 05-02-2009
khdani
Quote:

I think he means where each digit of the number is different.
Ex. 12345, 12346, 12347, 23456, 23457...
exactly

Quote:

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

Quote:

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
• 05-02-2009
quzah
Well get to work. I don't see you doing anything with all of our suggestions.

Quzah.
• 05-03-2009
khdani
Quote:

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
• 05-03-2009
stevesmithx
Quote:

Originally Posted by khdani
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.