Sqrt() function in C

Sqrt() function in C

What is sqrt() function in C ?

In C programming, sqrt() function is used to find out the square root of a number. sqrt() function is one of the pre-defined function in C programming, stored in math.h header file. We can use sqrt() function, after including math.h header file in the starting of our program.
There are many other library functions and header files available in C programming language, you can study about them on our library functions in C page

How to use sqrt()

sqrt() function in C programming is a double type function, that is it returns value in decimal format. This function works with int, short, byte long, double and float datatypes, but sometimes, on some compilers it may give an error while using any datatype other than double.

Syntax for sqrt() function

  • sqrt( integer );

Let’s take a sample code, and understand how to use sqrt() functiion

C code for using sqrt() function

int main()
    double ans=0.0;
    int a = 25;
    ans= sqrt(a);
    printf("The square root of %d is %f",a,ans);

    return 0;
The square root of 25 is 5.000000