/* HardCore SoftWare - Arbitrary Precision Factorial Finder (C) 2002, Fractal (Doug Hoyte) of HardCore SoftWare (www.hcsw.org) This software is protected by the GNU GPL, see www.fsf.org compilation: gcc fact.c -o fact */ #include #define MAXDIGITS 10000 int char2num(char tp) { if (tp == '\0') return 0; return (int) tp - 48; } int num2char(char tp) { return (int) tp + 48; } void alpha2mp(char *alpha, char *mp) { int i,len = strlen(alpha); memset(mp, '\0', MAXDIGITS); for (i=0; i < len; i++) mp[i] = alpha[len-i-1]; } void mp2alpha(char *mp, char *alpha, int maxlen) { int i,len = strlen(mp); memset(alpha, '\0', maxlen); for (i=0; (i < len) && (i < maxlen); i++) alpha[i] = mp[len-i-1]; } void add2mps(char *mp1, char *mp2) { int tp,i=0,carry=0; while((mp1[i] != '\0') || (mp2[i] != '\0')) { tp = char2num(mp1[i]) + char2num(mp2[i]) + carry; if (tp > 9) carry=1; else carry = 0; tp %= 10; mp1[i] = num2char(tp); i++; } if (carry) mp1[i] = '1'; } /* Doesn't work for numbers < 1 */ void multmp(char *mp1, int imp2) { char tp[MAXDIGITS]; int i; memset(tp, '\0', MAXDIGITS); strcpy(tp, mp1); for(i=0; i1; imp--) multmp(mp, imp); } usage() { fprintf(stderr, "HCSW Factorial Finder\n\nusage: fact \n\n"); exit(0); } main (int argc, char *argv[]) { char tp[MAXDIGITS]; char tp2[MAXDIGITS]; int i; if (argc != 2) usage(); for (i=0; i