C语言中求平方根的函数是sqrt
函数原型: double sqrt(double x);和 float sqrt(float x);
头文件:#include <math.h>
参数说明:x 为要计算平方根的值
返回值:返回 x 平方根
注意事项:如果 x < 0,将会导致 domain error 错误。
示例计算20的平方根值:
1
2
3
4
5
6
7
8
9
10
11
|
#include <math.h>
#include <stdio.h>
int
main(){
double
root;
root =
sqrt
(20);
printf
(
"answer is %f\n"
, root);
return
0;
}
/*
输出:answer is 4.4721
*/
|