Can you please answer the following question! The program is in JavaScript and must contain readlineSync. Thank you! If you have a number and you want to find its square root, you can start by guessing about the answer, x0, and then improve the guess with the following formula: x1 =(x0 + a/x0) / 2 Let's look at a specific example. Let's say I asked you to tell me the square root of 9, and we start with x0 = 6, then x1 = (6 + 9/6) / 2 = 3.75, which is closer. We can repeat the procedure, using x1 to calculate x2, and so on. In this case, x2 = 3.075 and x3 = 3.00091. So it converges quickly on the correct answer. Write a program called square_root.js that asks the user for a decimal number and returns an approximation of the square root of that number, using this technique. You should not use Math.sqrt. As your initial guess, you should use a/2. Your program should iterate until it gets two consecutive estimates that differ by less than 0.0001. You can use Math.abs to calculate the absolute value of the difference. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs Approximating Square Roots: https://youtu.be/LIh3NFtu_l4
Can you please answer the following question! The
If you have a number and you want to find its square root, you can start by guessing about the answer, x0, and then improve the guess with the following formula:
x1 =(x0 + a/x0) / 2
Let's look at a specific example. Let's say I asked you to tell me the square root of 9, and we start with x0 = 6, then x1 = (6 + 9/6) / 2 = 3.75, which is closer. We can repeat the procedure, using x1 to calculate x2, and so on. In this case, x2 = 3.075 and x3 = 3.00091. So it converges quickly on the correct answer.
Write a program called square_root.js that asks the user for a decimal number and returns an approximation of the square root of that number, using this technique. You should not use Math.sqrt.
As your initial guess, you should use a/2. Your program should iterate until it gets two consecutive estimates that differ by less than 0.0001. You can use Math.abs to calculate the absolute value of the difference. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs
Approximating Square Roots: https://youtu.be/LIh3NFtu_l4
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images