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
*/
|