home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
MBUG
/
MBUG003.ARC
/
JRTPAS-1.LBR
/
JRT25.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1979-12-31
|
1KB
|
34 lines
{Program 4.6
NOTE: Have patience with this one. I thought it was broke
until I looked at the code carefully. It takes
awhile. JRT took ten minutes,(I didn't use a stop
watch) while Pascal/Z took 5 minutes. But JRT
had more digit accuracy.
computer 1 - 1/2 + 1/3 - ... + 1/9999 - 1/10000, 4 ways:
1) left to right, in succession
2) left to right, all pos and neg terms, then subtract
3) right to left in succession
4) right to left, all pos and neg terms, then subtract}
Program summing;
var s1, s2p, s2n, s3, s4p, s4n, lrp, lrn, rlp, rln : real;
i : integer;
begin
s1 := 0; s2p := 0; s2n := 0; s3 := 0; s4p := 0; s4n := 0;
for i := 1 to 5000 do
begin
lrp := 1/( 2 * i - 1 ); {pos terms, left to right}
lrn := 1/( 2 * i ); {neg terms, left to right}
rlp := 1/( 10001 - 2 * i ); {pos terms, right to left}
rln := 1/( 10002 - 2 * i ); {neg terms, right to left}
s1 := s1 + lrp - lrn;
s2p := s2p + lrp; s2n := s2n + lrn;
s3 := s3 + rlp - rln;
s4p := s4p + rlp; s4n := s4n + rln;
end;
writeln( s1, s2p - s2n );
writeln( s3, s4p - s4n )
end.