Latest web development tutorials

C Library Functions - sqrt ()

C standard library - <math.h> C standard library - <math.h>

description

C library functiondouble sqrt (double x) Returns the square root of x.

statement

Here is () statement sqrt function.

double sqrt(double x)

parameter

  • x - floating-point value.

return value

This function returns the square root of x.

Examples

The following example demonstrates the sqrt () function is used.

#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);
}

Let's compile and run the above program, which will result in the following:

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

C standard library - <math.h> C standard library - <math.h>