Subj : Re: sqrt algo To : comp.programming From : gerard46 Date : Thu Jul 14 2005 12:34 am | himanshu bafna wrote: | Can anyone shed light on an Algorithm for finding out the square root of | a number? to make it simple lets only consider integers. Here is an algorithm written in REXX to calculate the integer square root of X (no check is made for a negative X, however). __________________________________________________________ intsq: procedure; arg x; x=3Dtrunc(x); r=3D0; q=3D1 do while q<=3Dx; q=3Dq*4; end do while q>1 q=3Dq%4 _=3Dx-r-q r=3Dr%2 if _>=3D0 then do x=3D_ r=3Dr+q end end return r ___________________________________________________________ what ya need to know: DO WHILE checks at the top of the loop, percent (%) is integer divide, TRUNC(x) takes the integer part of the number X, and that's it. _______________________________________________________Gerard S. .