c 迭代公式

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/a1376871144/article/details/83479184

#include<stdio.h>
#include<math.h>
int main()
{  
    float a,x0,x1;
    printf("enter a positive number:");
    scanf("%f",&a);
    x0=a/2;
    x1=(x0+a/x0)/2;
    do
    { x0=x1;
      x1=(x0+a/x0)/2;
    }
    while(fabs(x0-x1)>1e-5);
    printf("the squre root of %5.2f is %8.5f\n",a,x1);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/a1376871144/article/details/83479184