1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <stdio.h> #define EPS 1e-10 float my_sqrt(float x){ float S=x, a=1,b=x; while(fabs(a-b)>EPS) { a=(a+b)/2; b = S / a; } return (a+b)/2; } int main() { printf("%f\n", my_sqrt(1e22)); return 0; }
1
99999998890.981537