sqrt
Square root function
Interface
#include <math.h>
double | sqrt (double x) |
long | sqrtl (long double x) |
float | sqrtf (float x) |
#include <complex.h>
complex | sqrt (complex x) |
double complex | csqrt (double complex x) |
float complex | csqrtf (float complex x) |
long double complex | csqrtl (long double complex x) |
Description
The sqrt function computes the non-negative square root of x, i.e sqrt(x)Example:
Example - Square root function
Workings
#include <stdio.h> #include <math.h> int main() { double x = 1234321; double result = sqrt(x); printf("The square root of %.2lf is %.2lf\n", x, result); return 0; }
Solution
Ouput:
The square root of 1234321.00 is 1111.00
Special Values
sqrt ( -0 ) returns -0. sqrt ( x ) returns a NaN and generates a domain error for x < 0.Compatibility
DOS | UNIX | Windows | ANSI C | C++ only | |
---|---|---|---|---|---|
sqrtl | • | • | |||
Real sqrt | • | • | • | • | |
Complex sqrt | • | • | • | ||
Complex csqrt | • | • |
Last Modified: 18 Dec 11 @ 13:08 Page Rendered: 2022-03-14 16:08:08