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 calculate the number of daffodils in C language

2025-04-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

How to use C language to find out the number of daffodils, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Topic description

Find out all the daffodils.

Analysis.

Encyclopedia of Baidu: the number of daffodils (Narcissistic number) is also known as pluperfect digital invariant, PPDI, narcissism, self-power, Armstrong or Armstrong number. The number of daffodils refers to a three-digit number, and the sum of the third power of the number in each digit is equal to itself. For example: 13 + 53 + 33 = 153.

To judge whether a number is the number of daffodils, you can first take out all the bits of the number and put it into the array, and finally put in the formula of the number of daffodils. If the condition of daffodils is satisfied, the number is the number of daffodils.

The code implements # include # define INTEGER_MAXIMUM 999 / / numeric range, maximum # define INTEGER_MINIMUM 100 / / minimum int if_narcissistic_number (int num); int main () {int I = 0; for (I = INTEGER_MINIMUM; I 999) return 0; int hundreds = num / 100; / / 100-digit int tens = num / 10% 10; / 10-digit int ones = num% 10 / / individual bit if (num = = hundreds * hundreds * hundreds +\ tens * tens * tens +\ ones * ones * ones) return 1; return 0;} run result

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

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