(e-mail address removed) said:
How about this little factorial program? I think it's pretty cute.
<snip>
Here are some results from that program:
../foo
Segmentation fault (core dumped)
../foo -h
1
../foo 0 /* it actually gets this right, which was a mild surprise */
1
Every non-negative integer argument up to and including 12 works fine,
but observe what happens when we exceed 12:
../foo 13
1932053504
(the correct value is of course 6227020800).
So you have a seriously convoluted program which only works for a
vanishingly small percentage (less than 0.2%) of possible valid inputs.
My own factorial program is, alas, twice as long as yours (58 lines),
not including library code of course - but it continues to get the
answers right long past 13, despite not taking advantage of ISO's
licence to write into argv. For example, compare this:
../foo 52
0
with this:
~/path/to/rjhfactorial 52
80658175170943878571660636856403766975289505440883277824000000000000