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.

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.

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.

Syntax for sqrt() function

sqrt( integer );

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

C code for using sqrt() function

Run
#include  // header files
#include  // library files

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

    return 0;
}

Output:

The square root of 25 is 5.000000

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription