Hi everyone,
Is there a way to find the square root of a value without Karel (SQRT fonction)?
Thank you
Hi everyone,
Is there a way to find the square root of a value without Karel (SQRT fonction)?
Thank you
Lookout for Heron's Method. With that you can write your own program to calculate the square root.
There is a TP-instruction for this, but it's only included in the Math function option J593 as far as I'm aware.
Newton's method can take a while unless you accept looser accuracy, but should be possible to implement in TP:
You are right. And surprise, surprise: that Math function package is more or less a collection of small Karel programs you can call from TP.
Thank you all for your answers,
I found the Babylonian method for finding a square root.
Here is the code for it:
double sqrt(double number)
{ double error = 0.00001; //define the precision of your result double s = number;
while ((s - number / s) > error) //loop until precision satisfied { s = (s + number / s) / 2; } return s;
}
now i will do some tests and compare between this ans sqrt fonction in karel lanuage to see if this is enough for my application
Thank you again