#include <stdio.h>
#include <math.h>
int main()
{
double x1=1.0, x2, a;
printf(“请输入a:”);
scanf("%lf", &a);
x2 = (1 + a) / 2;
while (fabs(x1-x2) > 1e-5)
{
x1 = x2;
x2 = (x1 + a / x1) / 2;
}
printf("%f\n%f\n", x1, x2);
}
用迭代法求x=sqrt(a)
最新推荐文章于 2022-09-28 16:53:23 发布