Jump to content

Nth root: Difference between revisions

Nth root en TrueBASIC
m (→‎{{header|COBOL}}: added missing <lang cobol>)
(Nth root en TrueBASIC)
Line 3,295:
7131.5
49.0</pre>
 
=={{header|True BASIC}}==
<lang qbasic>FUNCTION Nroot (n, a)
LET precision = .00001
 
LET x1 = a
LET x2 = a / n
DO WHILE ABS(x2 - x1) > precision
LET x1 = x2
LET x2 = ((n - 1) * x2 + a / x2 ^ (n - 1)) / n
LOOP
LET Nroot = x2
END FUNCTION
 
PRINT " n 5643 ^ 1 / n nth_root ^ n"
PRINT " ------------------------------------"
FOR n = 3 TO 11 STEP 2
LET tmp = Nroot(n, 5643)
PRINT USING "####": n;
PRINT " ";
PRINT USING "###.########": tmp;
PRINT " ";
PRINT USING "####.########": (tmp ^ n)
NEXT n
PRINT
FOR n = 25 TO 125 STEP 25
LET tmp = Nroot(n, 5643)
PRINT USING "####": n;
PRINT " ";
PRINT USING "###.########": tmp;
PRINT " ";
PRINT USING "####.########": (tmp ^ n)
NEXT n
END</lang>
 
=={{header|Ursala}}==
2,136

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.