How to resolve the algorithm Nth root step by step in the AWK programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Nth root step by step in the AWK programming language
Table of Contents
Problem Statement
Implement the algorithm to compute the principal nth root
A
n
{\displaystyle {\sqrt[{n}]{A}}}
of a positive real number A, as explained at the Wikipedia page.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Nth root step by step in the AWK programming language
Source code in the awk programming language
#!/usr/bin/awk -f
BEGIN {
# test
print nthroot(8,3)
print nthroot(16,2)
print nthroot(16,4)
print nthroot(125,3)
print nthroot(3,3)
print nthroot(3,2)
}
function nthroot(y,n) {
eps = 1e-15; # relative accuracy
x = 1;
do {
d = ( y / ( x^(n-1) ) - x ) / n ;
x += d;
e = eps*x; # absolute accuracy
} while ( d < -e || d > e )
return x
}
You may also check:How to resolve the algorithm Knuth's power tree step by step in the Racket programming language
You may also check:How to resolve the algorithm Peaceful chess queen armies step by step in the ATS programming language
You may also check:How to resolve the algorithm Append a record to the end of a text file step by step in the Nim programming language
You may also check:How to resolve the algorithm Enumerations step by step in the Computer/zero Assembly programming language
You may also check:How to resolve the algorithm Color of a screen pixel step by step in the M2000 Interpreter programming language