Pregunta de entrevista de AEYE Health

Find the square root using arithmetic actions. Use kind of binary search.

Respuesta de la entrevista

Anónimo

21 nov 2023

For example, find the square root of 121. Divide 121 by 2. You get 60(ignore remainder). 60*60>121 then divide 60 by 2. You get 30. 30*30>121 then divide 30 by 2. You get 15. 15*15>121 then divide 15 by 2. You get 7. 7*7<121. Now you know that the result is between 7 and 15. So create loop like: for(int i=7;i<=15;i++){ if(i*i=121){ return i;// this is the root square } }