Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the judgment of complete Square Integer in C language

Shulou Source: shulou.com Published: 2022-06-02 04:56:51 10月01日 Update

This article mainly shows you "C language how to achieve complete square integer judgment", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "C language how to achieve complete square integer judgment" this article.

1. Principle:

The judgment of complete square integer is realized by using sqrt-square root function.

Second, function

1. Original form:

# include... double sqrt (double x)

two。 Parameter: X represents the number of square roots to be found.

Note: in this article, x is defined as an integer.

3. Return value: if the function call is successful, the square root of the parameter x is returned.

If x is NaN (Not a Number) or a negative number, the value NaN is returned.

3. Analysis:

The return value of the sqrt function is a floating-point number. We pass the complete square integer to the function whose return value should be the floating-point type of the square root of the number, and force the return value to be the integer whose value should be equal to itself, while we pass the non-square integer into the function and the return value should also be the floating-point type of the square root of the number, but the value of the returned value should not be equal to itself if we convert the return value to the integer. Using this point, we realize the judgment of complete square integers.

For example:

# include # include int main () {int astat4; printf ("% g% d", sqrt (a), (int) sqrt (a)); putchar ('\ n'); int baked 3; printf ("% g% d", sqrt (b), (int) sqrt (b)); return 0;}

Running result:

4. Examples:

Write a function, using parameters to pass in a 3-digit number, to find out all the numbers between 101~number that meet the following two conditions: it is a complete square, and there are two digits the same, such as 144,676, etc., the function returns the number of such data. Write the main function at the same time.

# include # include int func (int); int func (int x) {int i; int count=0; int T1 notebook t2direction t3; for (iLife101 Tinci)

Tags: Function integer square root language content parameter floating point article learning help compulsion same success two number between representative digit prototype principle Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL vpn NVidia Apple macOS