Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Write a program to find out the factorial of any number.:confused:
Posted
Updated 21-Oct-10 23:40pm
v2
Comments
Sandeep Mewara 22-Oct-10 7:26am    
No effort!

Tough job, if not impossible! I don't fancy trying to write this. One problem with computers are they're finitely bounded and the set of positive integers isn't...

Cheers,

Ash

PS to CPallini's comment: I may be wrong by I thought factorials were only defined for integers and zero. I'd be interested in (although probably wouldn't understand) any references to non-integral factorials in either pure or applied maths if you've got any to hand.

PPS: And of course now doing a search for "factorial non-integer" I've got more than enough to ruin my weekend!
 
Share this answer
 
v3
Comments
CPallini 22-Oct-10 5:35am    
You're bounded too ('any number' is in a broader set than the one of the 'positive integers') :-)
CPallini 22-Oct-10 8:18am    
I've a couple of arguments:
[1.The facetious] prog_fact(any_number) {if (any_number in Natural) return any_number! else throw;}
[2.The more facetious] en.wikipedia.org/wiki/Gamma_function
For a reasonable subset of the natural numbers (see Aescleal's caveat), the task is almost trivial, just an iteration (and there is sample code available all around you...).
Please, start coding!
:)
 
Share this answer
 
v2
The code to compute the factorial is trivial so you can write it by yourself; the only problem could be the size of numbers you want to deal with.
If you use the native types provided by your compiler, you have this limits:


  • an unsigned int (32 bit in size) can hold at most 12!
  • an unsigned __int64 (64 bit in size) can hold at most 20!


If you want to handle the factorial of numbers bigger than 20, you should use a library for big-integers (like the ones used to handle the numbers involved in RSA cipher, which are 1024 bit and more). See http://www.google.it/#hl=it&source=hp&biw=1676&bih=877&q=bigint+c%2B%2B&aq=f&aqi=&aql=&oq=&gs_rfai=&fp=65414bacc8cbde34[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900