赞
踩
#include<stdio.h>
const double EPSINON=1e-10;
// 二分法控制精度 例子:求sqrt(2) 的精确值
int main()
{
double low=1.4;
double high=1.5;
double mid=(low+high)/2;
while (high-low>EPSINON){
if (mid*mid<2)
low=mid;
else
high=mid;
mid=(high+low)/2;
}
printf("%.9lf", mid);
return 0;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。