![Computers and Technology](/tpl/images/cats/informatica.png)
Computers and Technology, 23.10.2019 17:30, marlesly87
Given a double variable named x that has been declared and given a value, let's use a binary search technique to assign an estimate of its square root to another double variable, root that has also been declared. let's assume that x's value is greater than 1.0 -- that will simplify things a bit. here's the general idea: since x> 1, we know its square root must be between 1 and x itself. so declare two other variables of type double (a and b say) and initialize them to 1 and x respectively. so we know the square root must be between a and b. our strategy is to change a and b and make them closer and closer to each other but alway make sure that the root we're looking for is between them. (such a condition that must always hold is called an invariant.) to do this we will have a loop that at each step finds the midpoint of a and b. it then squares this midpoint value and if the square of the midpoint is less than x we know that the root of x must be bigger than this midpoint: so we assign the midpoint to a (making a bigger and shrinking our a and b interval by and we still can be sure that the root is between a and b. of course if the midpoint's square is greater than x we do the oppo we assign b the value of midpoint. but when to stop the loop? in this exercise, just stop when the interval between a and b is less than 0.1 and assign root the midpoint of a and b then.
![answer](/tpl/images/cats/otvet.png)
Answers: 3
Similar questions
![Предмет](/tpl/images/cats/informatica.png)
Computers and Technology, 30.10.2019 22:31, taylorbean315
Answers: 2
![Предмет](/tpl/images/cats/informatica.png)
Computers and Technology, 30.10.2019 22:31, lobatospitones
Answers: 1
![Предмет](/tpl/images/cats/informatica.png)
Computers and Technology, 04.12.2019 01:31, redthangracing
Answers: 1
Do you know the correct answer?
Given a double variable named x that has been declared and given a value, let's use a binary search...
Questions in other subjects:
![Konu](/tpl/images/cats/biologiya.png)
![Konu](/tpl/images/cats/biologiya.png)
Biology, 17.12.2020 02:00
![Konu](/tpl/images/cats/fr.png)
![Konu](/tpl/images/cats/mat.png)
![Konu](/tpl/images/cats/istoriya.png)
![Konu](/tpl/images/cats/geografiya.png)
![Konu](/tpl/images/cats/mat.png)
Mathematics, 17.12.2020 02:00
![Konu](/tpl/images/cats/obshestvoznanie.png)
Social Studies, 17.12.2020 02:00
![Konu](/tpl/images/cats/en.png)
![Konu](/tpl/images/cats/mat.png)
Mathematics, 17.12.2020 02:00