The function sqrt() takes a single argument (in double ) and returns the square root(also in double ). 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.
/*
Write a program to illustrate sqrt math function of C.
*/
Write a program to illustrate sqrt math function of C.
*/
#include<stdio.h>
#include<math.h>
main()
{
double number, result;
printf("Enter a number = ");
scanf("%lf",&number);
result = sqrt(number);
printf("Square root of %lf = %lf", number, result);
return 0;
}
Output:
Enter a number = 4.0
Square root of 4.0 = 2.0
0 Comments