关于c语言的一个程序算法

问题描述:

img

Inputa realnumber(0≤≤10°),output itssquareroot with error lessthan 10using bisectionalgorithm.
输入格式
Inputarealnumber
输出格式
Outputitssquareroot.
样例
input
 932282158.6512308
output
 input
 566010284.599082
 output
23664.53643319
 input
 922313882.8472252
 output
 39369.62195206

#include <stdio.h>
int main()
{
    double a;
    scanf("%lf",&a);
    double m = 0;
    double n = a/2;
    double d = 0;
    while(1)
    {
        d = (m+n)/2;
        if(fabs(d*d - a) <= 1e-6)
        {
            printf("%lf\n",d);
            break;
        }
        if(d*d > a)
            n = d;
        else if(d*d < a)
            m = d;
    }
return 0;
}