2012-06: Maths
Write a program to accurately calculate the cube root of an input number (between 1 and 1000) without using any of the Math methods.
Scrivi un programma per calcolare accuratamente la radice cubica di un numero da 1 a 1000 senza utilizzare le funzioni della libreria matematica.
Soluzione
Effettua una ricerca binaria della radice cubica…
TextWindow.Write("Numero da 1 1000: ")
n=TextWindow.ReadNumber()
' --------------------------------------------------------------
minimo =1
massimo=10
errore =1
' --------------------------------------------------------------
While(errore > 0.00001)
x=(minimo+massimo)/2
' TextWindow.WriteLine(minimo + " - " + x + " - " + massimo)
x3=x*x*x
errore=n-x3
if(errore > 0) Then
minimo=x
ElseIf(errore < 0) Then
massimo=x
EndIf
errore=Math.Abs(errore)
EndWhile
' --------------------------------------------------------------
TextWindow.WriteLine("Radice cubica di " + n + " = " + x)