Article View: comp.lang.pascal.misc
Article #66Re: Tough FACTORIAL math problem...
From: Sundial Services
Date: Wed, 06 Mar 1996 14:59
Date: Wed, 06 Mar 1996 14:59
49 lines
1870 bytes
1870 bytes
In article <4gsn1d$ia@epervier.CC.UMontreal.CA> pigeons@JSP.UMontreal.CA (PIGEON Steven) writes:
>Harlan Messinger (gusty@clark.net) wrote:
>: void getLastFactorialDigits(int results[], // assume sufficient space
>: // was preallocated (n+1 bytes)
>: int n) {
>:
>: results[0] = 1;
>: results[1] = 1;
>: for (int i = 2; i <= n; ++i) {
>: results[i] = results[i - 1] * i;
>: while (results[i] % 10 == 0)
>: results[i] /= 10;
>: results[i] = results[i] % 10;
>: }
>: return;
>: }
>Ah a! In PASCAL!!! :-) This is a Pascal group!
> function zerofacto(n:integer):integer;
> var s,j,i:longint;
> begin
> s:=1;
> j:=1;
> i:=0;
> while (j<=n) do
> begin
> s:=s*j;
> while ( (s>10) and (s mod 10=0)) do
> begin
> s:=s div 10;
> inc(i);
> end;
> s:=s mod 10;
> inc(j);
> end;
> zerofacto:=s mod 10;
> end;
Since there are less than 69 factorials that can be represented in most real
number systems, this would be a great place for a table-lookup. Calculate
them once and store them in a constant array.
Technical Details
Message-ID:
<sundial.2503.0035ADFA@primenet.com>Path:
arc1-ca.pugleaf.net!ip058.phx.primenet.com!sundialReferences:
<4fr8be$ass@news.iconn.net> <4g2agv$29r@clarknet.clark.net> <4gsn1d$ia@epervier.CC.UMontreal.CA>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!ip058.phx.primenet.com!sundial From: sundial@primenet.com (Sundial Services) Newsgroups: comp.lang.pascal.misc,comp.lang.c++,comp.lang.c,comp.lang.pascal.borland Subject: Re: Tough FACTORIAL math problem... Date: 6 Mar 1996 07:59:02 -0700 Organization: Primenet Sender: root@primenet.com Distribution: world Message-ID: <sundial.2503.0035ADFA@primenet.com> References: <4fr8be$ass@news.iconn.net> <4g2agv$29r@clarknet.clark.net> <4gsn1d$ia@epervier.CC.UMontreal.CA> X-Posted-By: ip058.phx.primenet.com X-Newsreader: Trumpet for Windows [Version 1.0 Rev B final beta #4]