Problem # 28 : Factorials

The factorial of a number is defined as the product of all numbers between 1 and the number, including them both.
So the factorial of 3 = 3 x 2 x 1 = 6, while that of 5 = 5 x 4 x 3 x 2 x 1 = 120. (Factorials of negative numbers are not defined, while that of 0 is defined as 1). The factorial operation is represented by an exclamation mark (!). Thus the factorial of 3 is represented by 3! = 12.

Most calculators cannot generate the factorial of large numbers (say greater than 20) accurately, ie, they can just give the first few digits correctly. Try finding 20! with any calculator, even the one that comes with Windows (not that I wish to imply Windows has some sort of superior calculator :-). You won't get many accurate digits.

The task is to find, accurately, the factorials of numbers which them calculators cannot compute. So write a program which returrns the factorial of numbers less than 60. Use a sub-routine, function, whatever you want. No technical specs for your program in this problem. (Actually, go for numbers greater than 60. The upper limit would probably be a function of the limits of your compiler. My QBasic program could find out 100!, didn't try higher numbers. C++ would obviously be able to handle even larger numbers faster).

Sample Output
Use this to check your program.
 0! = 1
 3!=6
 7!=5040
15!=1307674368000
20!=2432902008176640000
21!=51090942171709440000
22!=1124000727777607680000
30!=265252859812191058636308480000000
31!=8222838654177922817725562880000000
32!=263130836933693530167218012160000000
33!=8683317618811886495518194401280000000
34!=295232799039604140847618609643520000000
35!=10333147966386144929666651337523200000000
36!=371993326789901217467999448150835200000000
47!=258623241511168180642964355153611979969197632389120000000000
48!=12413915592536072670862289047373375038521486354677760000000000
49!=608281864034267560872252163321295376887552831379210240000000000
50!=30414093201713378043612608166064768844377641568960512000000000000
51!=1551118753287382280224243016469303211063259720016986112000000000000
52!=80658175170943878571660636856403766975289505440883277824000000000000
53!=4274883284060025564298013753389399649690343788366813724672000000000000
55!=12696403353658275925965100847566516959580321051449436762275840000000000000
56!=710998587804863451854045647463724949736497978881168458687447040000000000000
57!=40526919504877216755680601905432322134980384796226602145184481280000000000000
58!=2350561331282878571829474910515074683828862318181142924420699914240000000000000
59!=138683118545689835737939019720389406345902876772687432540821294940160000000000000
60!=8320987112741390144276341183223364380754172606361245952449277696409600000000000000


Previous Problem
Return to problems at The Vault
(Back to problems at The Vault )
Next Problem

LinkExchange
LinkExchange Member
1