C sqrt()

The sqrt() function computes the square root of a number.

Function prototype of sqrt()

double sqrt(double arg);

The function sqrt() takes a single argument (in double) and returns the square root (also in double).

[Mathematics]  √x = sqrt(x) [In C Programming]

The sqrt() function is defined in math.h header file.

To find square root of type int, float or long double, you can explicitly convert the type to double using cast operator.

int x = 0;
double result;
result = sqrt(double(x));

Also, you can use sqrtf() function to work specifically with float and sqrtl() to work with long double type.

long double sqrtl(long double arg );
float sqrtf(float arg );

Example: C sqrt() Function

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

int main()
    double num = 6, squareRoot;

    squareRoot =  sqrt(num);
    printf("Square root of %lf =  %lf", num, squareRoot);

    return 0;


Square root of 6.000000 =  2.449490