![]() |
|
#1
|
|||
|
|||
Factorial of numbersI've written a program to find all numbers where the factorial of the individual digits is the same as the number itself.
Example. 145 - 1!+4!+5! = 1+24+120 = 145 The program looks like this but it only seems to find numbers 1,2 & 145 but I'm sure there are more. CPP / C++ / C Code:
I'm not really good at coding so I'm sure it's "ugly" but does anyone see anything wrong with the code. Last edited by dsmith : 09-Jun-2004 at 05:10.
Reason: Please use [c] & [/c] for syntax highlighting
|
|
#2
|
||||
|
||||
|
Quote:
__________________
Age is unimportant -- except in cheese |
|
#3
|
||||
|
||||
|
Quote:
Hi, I just found out that they are unique factorials and here is all of those that exists: 1 = 1! 2 = 2! 145 = 1! + 4! + 5! 40585 = 4! + 0! + 5! + 8! + 5! there is no other integers like it (I think, I'm not a math guy) according to this: unique Factorials __________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds |
|
#4
|
||||
|
||||
|
Quote:
I also just confirmed 40585 too. I just tested thru 9999999 and those are the only 4. __________________
Age is unimportant -- except in cheese |
|
#5
|
||||
|
||||
|
Well that means you don't need a program then...
anyway, cior, your program works well and it displays all the 4 numbers although it took some time to get the last number (40585). Maybe we should focus on efficiency to get the numbers real fast. still, good work cior for able to code it.. __________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds |
|
#6
|
|||
|
|||
|
Thanks, I found out why the code doesn't work for me, 0! is actually 1 not 0. But the problem is that the I had to skip the inital zeroes and because of that I accidentally also skipped the zeroes within the number.
|
|
#7
|
|||
|
|||
|
Ok, I managed to rewrite the code to check if the next digit is higher than zero, if that's true 0! will be counted as 1 otherwise as 0.
CPP / C++ / C Code:
Last edited by dsmith : 09-Jun-2004 at 16:18.
Reason: Please use [c] & [/c] for syntax highlighting
|
|
#8
|
||||
|
||||
|
Now that you got it working, here's my solution:
CPP / C++ / C Code:
__________________
Age is unimportant -- except in cheese |
Recent GIDBlog
Welcome to Baghdad by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [CONTEST?]Data Structure Test | dsmith | C Programming Language | 2 | 06-Jun-2004 15:13 |
| Random numbers | KrissKross | C Programming Language | 5 | 13-May-2004 19:31 |
| Problem that doesn't make sense! Please help! | Shufty | C++ Forum | 23 | 09-May-2004 15:49 |
| c: array comparison | jack | C Programming Language | 7 | 26-Jan-2004 11:21 |
| Best way to validate numbers (ids)? | JdS | MySQL / PHP Forum | 1 | 20-Jan-2003 03:55 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The