求平方根(迭代法)

平方根的迭代:

#include <stdio.h>
#include "math.h "
int main()
{
    
    
    float x0,x1,a;
    scanf("%f",&a);
    x1=a/2;                               //先进行一次运算
    do
    {
    
    
        x0=x1;                       //运算值的替换
        x1=(x0+a/x0)/2;            //重复的公式
    }while(fabs(x0-x1)>=0.00001);//判断的条件
    printf("%.3f\n",x1);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_51907130/article/details/111199398