/* * Calculate a rough approximation of any factorial. Fast! * * To see how it works, take the decadic logarithm of any decimal number, * split it up by the digits before and after the decimal point, and examine * both numbers. Then, take the logarithm of a generic factorial and see what * happens. * "nachkomma" and "vorkomma" are the german words for the digits after and * before the decimal point, respectively. Because I don't know their english * words (postpoint and prepoint?), I left them as they are. * * Give any integer number on the command line ... * * Frank Pilhofer, 1995 * fp@fpx.de * * Copy freely with this message intact. */ #include #include #include int main (int argc, char *argv[]) { double nachkomma; long zahl, iter, vorkomma; zahl = atol (argv[1]); vorkomma = 0L; nachkomma = 0.0; for (iter=1; iter<=zahl; iter++) { vorkomma += (long) floor (log10 ((double) iter)); nachkomma+= fmod (log10 ((double) iter), 1.0); if (nachkomma >= 1) { vorkomma += 1L; nachkomma-= 1.0; } } printf ("Result: %ld! = %lf * 10^%ld\n", zahl, pow (10, nachkomma), vorkomma); return 0; }