Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Nth-root/ALGOL-W/nth-root.alg
Normal file
25
Task/Nth-root/ALGOL-W/nth-root.alg
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
begin
|
||||
% nth root algorithm %
|
||||
% returns the nth root of A, A must be > 0 %
|
||||
% the required precision should be specified in precision %
|
||||
long real procedure nthRoot( long real value A
|
||||
; integer value n
|
||||
; long real value precision
|
||||
) ;
|
||||
begin
|
||||
long real xk, xd;
|
||||
integer n1;
|
||||
n1 := n - 1;
|
||||
xk := A / n;
|
||||
while begin
|
||||
xd := ( ( A / ( xk ** n1 ) ) - xk ) / n;
|
||||
xk := xk + xd;
|
||||
abs( xd ) > precision
|
||||
end do begin end;
|
||||
xk
|
||||
end nthRoot ;
|
||||
% test cases %
|
||||
r_format := "A"; r_w := 15; r_d := 6; % set output format %
|
||||
write( nthRoot( 7131.5 ** 10, 10, 1'-5 ) );
|
||||
write( nthRoot( 64, 6, 1'-5 ) );
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue