编辑代码

#include <stdio.h>
float absolute(float a){
    if (a < 0){
        return 0 - a;
    }
    else{
        return a;
    }
}
float sqMy(int x, float epsilon){
    float res;
    res = 1;
    while (absolute(res * res - x) > epsilon)
    {
        res = (res + (x / res)) / 2; 
    }
        return res;
}
int main () {
    //JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。 
    printf("%f\n",sqMy(2, 0.01));
    return 0;
}