标签:scanf math 迭代 scan 1.0 形参 1.4 can clu
X1=1/2(x0+a/x0)
例如,a为2时,平方根值:1.414214
#include <stdio.h>
#include <math.h>
double fun(double a, dounle x0)
{ double x1, y;
x1=(x0+ a/x0)/2.0;
if( fabs(x1-x0)>=0.00001 )
y=fun(a,x1);
else y=x1;
return y;
}
main( )
{ double x;
printf("Enter x: "); scanf("%lf",&x);
printf("The square root of %lf is %lf\n",x,fun(x,1.0));
}
给定程序中函数fun的功能是:用递归算法求形参a的平方根。求平方根的迭代公式如下:
标签:scanf math 迭代 scan 1.0 形参 1.4 can clu
原文地址:http://www.cnblogs.com/lozjl/p/7775045.html