How To Use Square Root Function In C Program

Asked By 0 points N/A Posted on -
qa-featured

I am writing a  program in C which need to calculate the square root of  a  given number. Is there any square root function available in C library. How to implement it ?

SHARE
Answered By 0 points N/A #295397

How To Use Square Root Function In C Program

qa-featured

You don’t have to write functions for everything in C , it comes with some library function already available , you only need to use them by passing correct parameters and including the header files.

For using the square root function in C ,  <math.h> header file is required to be included in your program.

The declaration of sqrt function is:

double sqrt(double x)

 Here is a sample program to use square root function in a C program.

 Addition tip for users with GCC compiler(default on Linux distribution)

while compiling the file use the -lm tag at the end of command.

For e.g if the name of file is square.c , you can compile it by writing cc square.c -lm

Related Questions