Home > Article > Computer Tutorials > What is the header file where the sqrt function is located?
The header file name of the library function sqrt() is #include
The square root function in C language is double sqrt(double). The parameter is double, and the return value may be double or int. The function header file is #include
Extended information:
The input parameters of the sqrt() function must be double type, and the return type is also double type. Therefore, we need to use a double variable to receive the returned value. If the input data is not of double type, we can use cast to convert it to double type. This ensures proper functioning and accuracy of the function.
Whether to perform cast depends on the formal parameters and return value type of the function. If you don't cast, some compilers will issue a warning, some will report an error, and some will just pass. Therefore, the decision on whether to perform a forced conversion needs to be made on a case-by-case basis.
In the C language, sqrt is the square root of a non-negative real number. sqrt is Square Root Calculations. This operation can test the floating point capability of the CPU.
x=sqrt(i 100) means taking the square root of i 100 and assigning it to x. After VC 2008, it is an overloaded function, and the prototype is float sqrt (float), double sqrt (double), double long sqrt (double long).
Extended information
c language features
1. C language is also very suitable for use with assembly language. Although the C language provides many low-level processing functions, it still maintains good cross-platform characteristics. C language programs written in a standard specification can be compiled on many computer platforms, even including some embedded processors (microcontrollers or (called MCU) and supercomputers and other operating platforms.
2. C language contains only 9 types of various control statements and only 32 keywords. The programming of the program is not strict and mostly uses lowercase letters, and many unnecessary parts are streamlined.
3. The statement structure is rarely related to the hardware, and the C language itself does not provide hardware-related input, output, file management and other functions. If such functions are required, it needs to be coordinated with various libraries supported by the compilation system. For programming, the C language has a very simple compilation system.
Reference source: Sogou Encyclopedia—square root calculation
Usage: Calculate the square root of a non-negative real number.
Function prototype: The function prototype of the math.h header file in VC6.0 is double sqrt(double);
Description: sqrt is SquareRootCalculations (square root calculation). This operation can test the floating point capability of the CPU.
Program example:
#include
#include
void main()
{
double a=25,s;
s=sqrt(a);
printf("s=%.2lf\n",s);
}
Extended information
Things to note when using the sqrt function
1. The result of the sqrt function is an arithmetic square root, that is, it cannot operate on negative values, nor can it output imaginary results.
2. If you need to get the negative value in the arithmetic square root, you should add a negative sign before the sqrt function.
3. The parameter of the sqrt function must be a non-negative value. If it is a negative value, the output will report an error, that is, the value is invalid; if the parameter is an undefined non-numeric variable, an error will also be reported after pressing Enter, that is, the variable name mistaken.
4. The calculation precision of the sqrt function is related to the precision set by the C language, and the precision can be changed by setting it.
The above is the detailed content of What is the header file where the sqrt function is located?. For more information, please follow other related articles on the PHP Chinese website!