Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report