
У кого есть немножечко времени уделите пожалуста.
Спасибочки заранее.
type
PArrInt = ^ArrInt;
ArrInt = Array[0 .. Pred(maxInt Div SizeOf(LongInt))] Of LongInt;
Function PiTest(szPi: PChar; Const nDigits: Integer): Boolean;
Var
i, c, f: LongInt;
d, e, b, g, r: LongInt;
a: PArrInt;
szCurDigit: Integer;
_s: String;
Begin
PiTest := False;
If nDigits > 54900 Then Begin
WriteLn('Error in PiTest(): n must be <= 54900'); Exit
End;
szCurDigit := 0;
d := 0;
c := (nDigits div 4 + 1) * 14;
GetMem(a, c * SizeOf(LongInt));
f := 10000;
For i := 0 To Pred( c ) Do
a^[ i ] := 20000000;
Dec(c, 14); b := c;
While b > 0 Do Begin
e := d mod f; d := e;
Dec(b);
While b > 0 Do Begin
d := d * b + a^[ b ];
g := (b shl 1) - 1;
a^[ b ] := (d mod g) * f;
d := d div g;
Dec(b)
End;
r := e + d div f;
If r < 1000 Then Begin
If r > 99 Then Begin
szPi[szCurDigit] := '0'; Inc(szCurDigit);
End
Else
If r > 9 Then Begin
szPi[szCurDigit] := '0'; Inc(szCurDigit);
szPi[szCurDigit] := '0'; Inc(szCurDigit);
End
Else Begin
szPi[szCurDigit] := '0'; Inc(szCurDigit);
szPi[szCurDigit] := '0'; Inc(szCurDigit);
szPi[szCurDigit] := '0'; Inc(szCurDigit);
End;
End;
Str(r, _s);
Move(_s[1], szPi[szCurDigit], Length(_s));
Inc(szCurDigit, Length(_s));
Dec(c, 14); b := c;
End;
FreeMem(a, c * SizeOf(LongInt));
szPi[szCurDigit] := #0;
PiTest := True
End;
Const
nDigits = 100;
var
szPi: PChar;
Begin
GetMem(szPi, nDigits+1);
WriteLn('PI Computation');
PiTest(szPi, nDigits);
WriteLn('The ', nDigits, ' of Pi are: '#13#10, szPi);
FreeMem(szPi, nDigits+1);
End.