C sqrt() library function

The function double sqrt(double x); returns the square root of x.

Function prototype of sqrt

double sqrt(double x);
  • x : A floating point value whose square root to be computed. It must be a positive number.

Return value of sqrt

It returns the square root of x. If x is negative, it causes a domain error.

C program using sqrt function

The following program shows the use of sqrt function to calculate square root of a number.

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

int main ()
  double x, result;
  printf("Enter a number\n");
  scanf("%lf", &x);
  result = sqrt(x);
  printf("Square root of %lf = %lf\n", x, result);
  return 0;

Enter a number
Square root of 49.000000 = 7.000000
Enter a number
Square root of 85.453000 = 9.244079