In C, the sqrt function is primarily providedSquare root calculationi.e., the reverse process of the squared operation. The function is declared in mathh , the prototype isdouble sqrt(double x), the parameter x is the number of the square root to be opened.
The function of the sqrt function can actually be replaced by the pow function, as long as the value of its second parameter is fixed at 05 is pow(x, 0..)5) This is because:The root opening operation is actually a case where the exponent is less than 1 in a power operation
In mathematics, due toNegative negative is positiveTherefore, each square operation will produce two numbers with equal values, one positive and one negative, but, in the C languageThe sqrt function returns only positive roots, which needs to be noted.
In C programming, to use the sqrt function to implement the open square root operation, of course, the first step is to introduce the mathThe h-function library, the second is to pass the number of the square to be opened into the sqrt function as a parameter, and finally use the result returned by the sqrt function.
Basic usage examples are as follows:
When the number to be opened is a square number, then the return result of the sqrt function is in the form of an integer, and when the number to be opened is not a square number, then the return result of the sqrt function is in the form of floating-point numbers, as shown below:
So, we can use the return result of the sqrt function to determine a numberWhether it is a square number or not, which is provided in CA functional function modf specifically for operations that take out fractional parts of floating-point numbers, illustrated by a case below:
For more uses of the return value of the SQRT function in the C language, please explore it in actual programming, which will not be introduced in this article.