How to solve the number of daffodils in C language

coldplay.xixi
Release: 2020-08-19 13:30:27
Original
4209 people have browsed it

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

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.

How to solve the number of daffodils in C language

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++;
}
}
Copy after login

How to solve the number of daffodils in C language

4. Press [F9] to compile as shown in the figure without errors. Press [F10] to run

How to solve the number of daffodils in C language

5. The running results are as shown in the figure. There are four daffodil numbers:

153, ​​370, 371, 407.

How to solve the number of daffodils in C language

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template