Latest web development tutorials

C 庫函數– sqrt()

C 標準庫 - <math.h> C標準庫- <math.h>

描述

C庫函數double sqrt(double x)返回x的平方根。

聲明

下面是sqrt() 函數的聲明。

double sqrt(double x)

參數

  • x --浮點值。

返回值

該函數返回x 的平方根。

實例

下面的實例演示了sqrt() 函數的用法。

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

int main ()
{

   printf("%lf 的平方根是 %lf\n", 4.0, sqrt(4.0) );
   printf("%lf 的平方根是 %lf\n", 5.0, sqrt(5.0) );
   
   return(0);
}

讓我們編譯並運行上面的程序,這將產生以下結果:

4.000000 的平方根是 2.000000
5.000000 的平方根是 2.236068

C 標準庫 - <math.h> C標準庫- <math.h>