Home > Article > Backend Development > How to solve the number of daffodils in C language
C language method to solve the narcissus number: first press [CTRL N] to create a new source code; then enter the source code of the narcissus number; then press [F9] to compile; finally, when no error is displayed, press [ F10】Run.
How to solve the narcissus number in c language:
1. First, what is the narcissus number?
The daffodil number refers to a 3-digit number, the sum of the 3rd power of the numbers in each digit is equal to itself (for example: 1^3 5^3 3^3 = 153).
2. Knowing what narcissus number is, we can open our compiler and write code. Open our compiler. The editor uses dev c. Press [CTRL] [N] to create a new one. source code.
3. Enter the code:
#include<stdio.h> #include<math.h> main() { int a,b,c,n; n = 100; while(n<1000) { a = (n % 10); b = (n/10%10); c = (n/100); if( n == pow(a,3) +pow(b,3) + pow(c,3)) printf("%d\t",n); n++; } }
4. Press [F9] to compile as shown in the figure without errors. Press [F10] to run
5. The running results are as shown in the figure. There are four daffodil numbers:
153, 370, 371, 407.
Related learning recommendations: C video tutorial
The above is the detailed content of How to solve the number of daffodils in C language. For more information, please follow other related articles on the PHP Chinese website!