凤
凤冠坡
Unregistered / Unconfirmed
GUEST, unregistred user!
原C程序部分:
void __fastcall TForm1::Button2Click(TObject *Sender)
{Const ARRSIZE=1010, DISPCNT=1000;
//定义数组大小,显示位数
char x[ARRSIZE], z[ARRSIZE];
//x[0] x[1] . x[2] x[3] x[4] .... x[ARRSIZE-1]
int a=1, b=3, c, d, Run=1, Cnt=0;
memset(x,0,ARRSIZE);
memset(z,0,ARRSIZE);
x[1] = 2;z[1] = 2;
while(Run && (++Cnt<200000))
d = 0;
for(int i=ARRSIZE-1;
i>0;
i--)
{c = z*a + d;
z = c % 10;
d = c / 10;
}
d = 0;
for (int i = 0;
i < ARRSIZE;
i + +)
{c = z+d*10;
z = c / b;
d = c % b;
}
//x+=z;
Run = 0;
for (int i = ARRSIZE - 1;
i > 0;
i - -)
{
c = x + z;
x = c%10;
x[i-1] += c/10;
Run |= z;
}
a + +;
b + = 2;
}
Memo1 - > Text = AnsiString().sprintf("计算了 %d 次rn", Cnt);
Memo1 - > Text = Memo1 - > Text + AnsiString().sprintf("Pi = %d%d.rn", x[0], x[1]);
for (int i = 0;
i < DISPCNT;
i + +)
{if(i && ((i%100)==0))
Memo1->Text = Memo1->Text + "rn";
Memo1->Text = Memo1->Text + (int)x[i+2];
}}
Delphi 过程部分:
........................
//公式:π = 2 + 2/3 + 2/3*2/5 + 2/3*2/5*3/7 + ...
const
ASize = 1010;
DCount = 1000;
var
A, B, C, D: integer;
I, Run, Cnt: integer;
S: string;
X, Z: array[0..ASize] of integer;
begin
S := '';
Cancel := False;
A := 1;
B := 3;
C := 0;
D := 0;
Run := 1;
Cnt := 0;
for i := 0 to ASize - 1do
begin
X := 0;
Z := 0;
end;
X[1] := 2;
Z[1] := 2;
while (Run > 0) and (Cnt < 2000000)do
begin
D := 1;
for i := ASize - 1do
wnto 1do
begin
c := Z * a + d;
Z := c mod 10;
d := c div 10;
end;
d := 0;
for i := 0 to ASize - 1do
begin
c := Z + d * 10;
Z := c div b;
d := c mod b;
end;
Run := 0;
for i := ASize - 1do
wnto 1do
begin
c := X + Z;
X := c mod 10;
x[i - 1] := x[i - 1] + c div 10;
Run := Run + Z mod 10;
end;
A := A + 1;
B := B + 2;
Cnt := Cnt + 1;
Application.ProcessMessages;
if Cancel then
break;
end;
Memo1.Text := Format('计算了 %d 次', [Cnt]);
Memo1.Text := Memo1.Text + Format('Pi =%d%d.'#13#10, [X[0], x[1]]);
for i := 0 to DCount - 1do
begin
if (i) mod 10 = 0 then
if I > 0 then
S := S + #32;
if (i) mod 50 = 0 then
if I > 0 then
S := S + #13#10;
S := S + Format('%d', [x[i + 2]]);
end;
Memo1.Text := Memo1.Text + S;
end;
void __fastcall TForm1::Button2Click(TObject *Sender)
{Const ARRSIZE=1010, DISPCNT=1000;
//定义数组大小,显示位数
char x[ARRSIZE], z[ARRSIZE];
//x[0] x[1] . x[2] x[3] x[4] .... x[ARRSIZE-1]
int a=1, b=3, c, d, Run=1, Cnt=0;
memset(x,0,ARRSIZE);
memset(z,0,ARRSIZE);
x[1] = 2;z[1] = 2;
while(Run && (++Cnt<200000))
d = 0;
for(int i=ARRSIZE-1;
i>0;
i--)
{c = z*a + d;
z = c % 10;
d = c / 10;
}
d = 0;
for (int i = 0;
i < ARRSIZE;
i + +)
{c = z+d*10;
z = c / b;
d = c % b;
}
//x+=z;
Run = 0;
for (int i = ARRSIZE - 1;
i > 0;
i - -)
{
c = x + z;
x = c%10;
x[i-1] += c/10;
Run |= z;
}
a + +;
b + = 2;
}
Memo1 - > Text = AnsiString().sprintf("计算了 %d 次rn", Cnt);
Memo1 - > Text = Memo1 - > Text + AnsiString().sprintf("Pi = %d%d.rn", x[0], x[1]);
for (int i = 0;
i < DISPCNT;
i + +)
{if(i && ((i%100)==0))
Memo1->Text = Memo1->Text + "rn";
Memo1->Text = Memo1->Text + (int)x[i+2];
}}
Delphi 过程部分:
........................
//公式:π = 2 + 2/3 + 2/3*2/5 + 2/3*2/5*3/7 + ...
const
ASize = 1010;
DCount = 1000;
var
A, B, C, D: integer;
I, Run, Cnt: integer;
S: string;
X, Z: array[0..ASize] of integer;
begin
S := '';
Cancel := False;
A := 1;
B := 3;
C := 0;
D := 0;
Run := 1;
Cnt := 0;
for i := 0 to ASize - 1do
begin
X := 0;
Z := 0;
end;
X[1] := 2;
Z[1] := 2;
while (Run > 0) and (Cnt < 2000000)do
begin
D := 1;
for i := ASize - 1do
wnto 1do
begin
c := Z * a + d;
Z := c mod 10;
d := c div 10;
end;
d := 0;
for i := 0 to ASize - 1do
begin
c := Z + d * 10;
Z := c div b;
d := c mod b;
end;
Run := 0;
for i := ASize - 1do
wnto 1do
begin
c := X + Z;
X := c mod 10;
x[i - 1] := x[i - 1] + c div 10;
Run := Run + Z mod 10;
end;
A := A + 1;
B := B + 2;
Cnt := Cnt + 1;
Application.ProcessMessages;
if Cancel then
break;
end;
Memo1.Text := Format('计算了 %d 次', [Cnt]);
Memo1.Text := Memo1.Text + Format('Pi =%d%d.'#13#10, [X[0], x[1]]);
for i := 0 to DCount - 1do
begin
if (i) mod 10 = 0 then
if I > 0 then
S := S + #32;
if (i) mod 50 = 0 then
if I > 0 then
S := S + #13#10;
S := S + Format('%d', [x[i + 2]]);
end;
Memo1.Text := Memo1.Text + S;
end;