If you wanted to use the inbuilt square root function in the C programming language, what would you have to do?

1 Answer | Add Yours

jgoulden's profile pic

jgoulden | College Teacher | (Level 1) Adjunct Educator

Posted on

In the C programming language, the square root functionality is included in a library. To use this function, you must include the following compiler directive at the top of your program:

#include <math.h>

Having done so, the square root functionality is invoked using the "sqrt" function. For example,

y = sqrt(x);

would compute the square root of the value stored in variable x and store the result in variable y.

If you wish to use this C language functionality in the C++ language, the compiler directive is a bit different:

#include <cmath>

and the usage is the same as above.

We’ve answered 317,644 questions. We can answer yours, too.

Ask a question