I guess it's pretty stupid to write the gamma function, when C already includes it (tgamma).
Remember that, for integers (n),
gamma(n) = (n-1)!.
(Below, you can see that as n grows, so does the error.)
(Also notice that, the output simulates the appearance of rain falling from thunderstorm clouds, when viewed from a distance. (I don't know if that is a mathematical property.))
' code ------------------------------------------------------------------------------------------------ #include <stdio.h> #include <math.h> int main() { char c; double i; for(i = 0.5; i<=40; i += 0.5) printf(".1f 0.10f\n", i, tgamma(i)); c = getchar(); return 0; } ' output ---------------------------------------------------------------------------------------------- 00.5 0000000000000000000000000000000000000000000000001.7724538509 01.0 0000000000000000000000000000000000000000000000001.0000000000 01.5 0000000000000000000000000000000000000000000000000.8862269255 02.0 0000000000000000000000000000000000000000000000001.0000000000 02.5 0000000000000000000000000000000000000000000000001.3293403882 03.0 0000000000000000000000000000000000000000000000002.0000000000 03.5 0000000000000000000000000000000000000000000000003.3233509704 04.0 0000000000000000000000000000000000000000000000006.0000000000 04.5 0000000000000000000000000000000000000000000000011.6317283966 05.0 0000000000000000000000000000000000000000000000024.0000000000 05.5 0000000000000000000000000000000000000000000000052.3427777846 06.0 0000000000000000000000000000000000000000000000120.0000000000 06.5 0000000000000000000000000000000000000000000000287.8852778150 07.0 0000000000000000000000000000000000000000000000720.0000000000 07.5 0000000000000000000000000000000000000000000001871.2543057978 08.0 0000000000000000000000000000000000000000000005040.0000000000 08.5 0000000000000000000000000000000000000000000014034.4072934834 09.0 0000000000000000000000000000000000000000000040320.0000000000 09.5 0000000000000000000000000000000000000000000119292.4619946090 10.0 0000000000000000000000000000000000000000000362880.0000000001 10.5 0000000000000000000000000000000000000000001133278.3889487856 11.0 0000000000000000000000000000000000000000003628800.0000000009 11.5 0000000000000000000000000000000000000000011899423.0839622486 12.0 0000000000000000000000000000000000000000039916800.0000000075 12.5 0000000000000000000000000000000000000000136843365.4655658574 13.0 0000000000000000000000000000000000000000479001600.0000001077 13.5 0000000000000000000000000000000000000001710542068.3195733000 14.0 0000000000000000000000000000000000000006227020800.0000007451 14.5 0000000000000000000000000000000000000023092317922.3142378032 15.0 0000000000000000000000000000000000000087178291200.0000104308 15.5 0000000000000000000000000000000000000334838609873.5564574599 16.0 0000000000000000000000000000000000001307674368000.0003223500 16.5 0000000000000000000000000000000000005189998453040.1263327700 17.0 0000000000000000000000000000000000020922789888000.0051576600 17.5 0000000000000000000000000000000000085634974475162.0572060300 18.0 0000000000000000000000000000000000355687428096000.0585764600 18.5 0000000000000000000000000000000001498612053315336.0709547900 19.0 0000000000000000000000000000000006402373705728001.1475086200 19.5 0000000000000000000000000000000027724322986333718.2905000000 20.0 0000000000000000000000000000000121645100408832033.2812000000 20.5 0000000000000000000000000000000540624298233507433.9061000000 21.0 0000000000000000000000000000002432902008176640607.4166000000 21.5 0000000000000000000000000000011082798113786906003.9520000000 22.0 0000000000000000000000000000051090942171709448099.1363000000 22.5 0000000000000000000000000000238280159446418474544.0000000000 23.0 0000000000000000000000000001124000727777607971802.0000000000 23.5 0000000000000000000000000005361303587544413749128.0000000000 24.0 0000000000000000000000000025852016738884984515607.0000000000 24.5 0000000000000000000000000125990634307293761521577.0000000000 25.0 0000000000000000000000000620448401733239552410000.0000000000 25.5 0000000000000000000000003086770540528697529220000.0000000000 26.0 0000000000000000000000015511210043330988264640000.0000000000 26.5 0000000000000000000000078712648783481796272090000.0000000000 27.0 0000000000000000000000403291461126605793833730000.0000000000 27.5 0000000000000000000002085885192762267589569090000.0000000000 28.0 0000000000000000000010888869450418354972400000000.0000000000 28.5 0000000000000000000057361842800962331239100000000.0000000000 29.0 0000000000000000000304888344611713895574200000000.0000000000 29.5 0000000000000000001634812519827426644042100000000.0000000000 30.0 0000000000000000008841761993739703670144000000000.0000000000 30.5 0000000000000000048226969334909066557884200000000.0000000000 31.0 0000000000000000265252859812191200035000000000000.0000000000 31.5 0000000000000001470922564714727341197000000000000.0000000000 32.0 0000000000000008222838654177925782278000000000000.0000000000 32.5 0000000000000046334060788513915613293000000000000.0000000000 33.0 0000000000000263130836933693625032901000000000000.0000000000 33.5 0000000000001505856975626701932920000000000000000.0000000000 34.0 0000000000008683317618811891588840000000000000000.0000000000 34.5 0000000000050446208683494507567950000000000000000.0000000000 35.0 0000000000295232799039604142308230000000000000000.0000000000 35.5 0000000001740394199580549821257590000000000000000.0000000000 36.0 0000000010333147966386148254900000000000000000000.0000000000 36.5 0000000061783994085110651212700000000000000000000.0000000000 37.0 0000000371993326789906364865600000000000000000000.0000000000 37.5 0000002255115784106522798538200000000000000000000.0000000000 38.0 0000013763753091226549819111800000000000000000000.0000000000 38.5 0000084566841903994709253311100000000000000000000.0000000000 39.0 0000523022617466599549516000000000000000000000000.0000000000 39.5 0003255823413303802954033000000000000000000000000.0000000000 40.0 0020397882081197472289204000000000000000000000000.0000000000
Bookmarks