HZNUOJ

【C系列4.15】问题二:单参数函数

Tags:  迭代
Time Limit:  1 s      Memory Limit:   128 MB
Submission:4992     AC:2185     Score:41.54

Description

编写一个函数,该函数用迭代法求平方根。求平方根的迭代公式为:

其中a 是需要求平方根的数。(主函数代码部分已经写好,只需写函数部分,如果提交的不是c语言则需要提交全部代码)

#include<stdio.h>
#include<math.h>

double happy(double a);
double a;

int main() {
    while (scanf("%lf", &a) != EOF) {
        printf("%.6lf ", happy(a));
    }
    return 0;
}

Input

输入实数a。

Output

输出a的平方根。答案精确到10-6.

Samples

input
8
output
2.828427

Hint

特别需要注意当a=0的情况。