#include <stdio.h>
#include <math.h>
double mysqrt(int n)
{
double x0,x1;
x0=1;
while(1)
{
x1=0.5*(x0+n/x0);
if(fabs(x1-x0)<1e-3)break;
x0=x1;
}
return x0;
}
int main()
{
printf("%f",mysqrt(10));
return 0;
}
参考链接:http://wenku.baidu.com/view/6b74c622bcd126fff7050bfe.html
本文介绍了一种使用迭代法计算平方根的手写C语言程序。该程序通过不断逼近的方法求解任意正整数的平方根,并与标准库函数进行对比验证准确性。
2060

被折叠的 条评论
为什么被折叠?



