C Standard Library

C <math.h> - sqrt() Function



The C <math.h> sqrt() function returns the square root of the given number.

Syntax

double sqrt (double x);
float sqrtf (float x);
long double sqrtl (long double x);

Parameters

x Specify a positive number.

Return Value

Returns the square root of the specified number.
If the x is negative, domain error occurs.

Example:

In the example below, sqrt() function is used to find out the square root of the given number.

#include <stdio.h>
#include <math.h>
 
int main (){
  printf("%lf\n", sqrt(25));
  printf("%lf\n", sqrt(30));
  printf("%lf\n", sqrt(35.5));
  printf("%lf\n", sqrt(50));  
  return 0;
}

The output of the above code will be:

5.000000
5.477226
5.958188
7.071068

❮ C <math.h> Library