Write a code which finds out the square root of a number, w/o sqrt() obviously.
SOLUTION
#define TOLERABLE_LIMIT 0.0000001
double square_root( double n){
double a=n, p=a*a, b;
while(p-n < TOLERABLE_LIMIT){
b = (a+n/a)/2;
a = b;
p = a*a;
}
return a;
}
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment