The sqrt() function is defined in the math.h header file. It helps to returns the square root of the given argument.
double sqrt(double x); #where x should be in double
Also, two functions sqrtf() and sqrtl() were used with type float and long double respectively.
float sqrtf(float x);
long double sqrtl(long double x);
The sqrt() function takes a single parameter in double. We can explicitly convert the type to double to find the square root of type int, float, or long double using the cast operator.
Parameter | Description | Required / Optional |
---|---|---|
double value | whose square root needs to be found | Required |
The return value of sqrt() function is a number in double.
Input | Return Value |
---|---|
double value | square root(in double) |
#include <stdio.h>
#include <math.h>
int main()
{
double N = 25, squareR;
squareR = sqrt(N);
printf("The Square root of given %lf is %lf", N, squareR);
return 0;
}
Output:
The Square root of given 25.000000 is 5.000000
#include <stdio.h>
#include <math.h>
int main () {
printf("The Square root of %lf is %lf\n", 4.0, sqrt(4.0) );
printf("The Square root of %lf is %lf\n", 5.0, sqrt(5.0) );
return(0);
}
Output:
The Square root of 4.000000 is 2.000000 The Square root of 5.000000 is 2.236068