home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
mbug
/
mbug003.arc
/
JRTPAS-1.LBR
/
JRT24B.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1979-12-31
|
512b
|
22 lines
{Program 4.5
compute the cosine using the expansion:
cos( x ) = 1 - x**2/( 2 * 1 ) + x**4/( 4 * 3 * 2 * 1 ) - ...}
Program cosine; { * ( input, output ) is implicit in Pascal/Z * }
const eps = 1.0E-14;
var x, sx, s, t : real;
i, k, n : integer;
begin
for i := 1 to n do
begin
read( x ); t := 1; k := 0; s := 1; sx := sqr( x );
while abs( t ) > eps * abs( s ) do
begin
k := k + 2; t := -t * sx/( k * ( k-1 ) ); s := s + t
end;
writeln( x, s, k div 2 )
end
end.