C語言 求平方根函數


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM