- This following code finds a square root for a given number.
- You can also find square root for a floating number.
- This code is using a Mathematical formula.
Here is the code
float squareRoot(float n){ float prev=0,cur=1;
while(prev!=cur)
{ prev=cur;
cur=0.5*(prev+(n/prev));
}
return cur;
} //Try this code..It works great..
5 comments:
Hats off to u..!
Awesome.. :)
Great job
its advisable not to compare floating point numbers since there may be imprecision in the representation of fps. And it precisely the reason why most compilers / functions dont use the above method. Not that those developers didn't know. :P
grt
Post a Comment