double sqrt(double arg);
The function sqrt() takes a single argument (in double) and returns the square root (also in double).
[Mathematics] √x = sqrt(x) [In C Programming]
The sqrt() function is defined in math.h header file.
To find square root of type int
, float
or long double
, you can explicitly convert the type to double
using cast operator.
int x = 0; double result; result = sqrt(double(x));
Also, you can use sqrtf()
function to work specifically with float and sqrtl()
to work with long double
type.
long double sqrtl(long double arg ); float sqrtf(float arg );
#include <stdio.h>
#include <math.h>
int main()
{
double num = 6, squareRoot;
squareRoot = sqrt(num);
printf("Square root of %lf = %lf", num, squareRoot);
return 0;
}
Output
Square root of 6.000000 = 2.449490
It takes a lot of effort and cost to maintain Programiz. We would be grateful if you support us by either:
Disabling AdBlock on Programiz. We do not use intrusive ads.
or
Donate on Paypal