C# Find the number of daffodils between 100-999. How many do you know? Let’s explore together!

Table of contents

background:

Extension:

Daffodil number example:

Effect display:​

Summarize:


background:

     Narcissistic number is also known as pluperfect digital invariant (PPDI), narcissistic number , exponentiation number , Armstrong number or Armstrong number . Narcissistic number refers to one. n is a positive integer that is a multiple of 3. The third power of the number in each digit is equal to itself. Then this is a narcissus number, such as 153. It is a narcissus number because 1³+5³+3³=153 .
The narcissus number is named after a mathematician in the early 19th century who discovered this interesting sequence and described it as a "perfect flower" because the digits in the numbers looked like petals. Narcissus only exists in single digits, double digits, and triple digits.

Extension:

The narcissus number is a type of autoexponential number. The names and numbers of other autoexponential numbers are as follows:

self-exponentiation

one person

three persons

four

five

Six

seven

eight bits

Nine

tenth place

name

Number of single people

Number of daffodils

four leaf rose number

Number of five-pointed stars

six combined numbers

Big Dipper Number

Eight Immortals

Number of Double Ninth Festival

perfect number

quantity

153、370、371、403

1634、8208、9474

54748、92727、93084

548834

1741725,4210818,9800817,9926315

1741725,4210818,9800817,9926315

1741725,4210818,9800817,9926315

1741725,4210818,9800817,9926315

Daffodil number example:

 int hundrd = 0;//定义一个整型变量 hundrd,并初始化为 0
 int ten = 0;//···
 int individul = 0;//···

 for (int i = 100; i <= 999; i++)//使用for循环遍历100-999之间的整数
 {
     hundrd = i / 100;//获取百位数字
     ten = i % 100 / 10;//获取十位数字
     individul = i % 100 % 10;//获取个位数字
     if (hundrd * hundrd * hundrd + ten * ten * ten + individul * individul * individul == i)//如果当前整数i是水仙花数,则满足以下等式:百位数的立方+十位数的立方+个位数立方等于当前整数i
     {
         Console.WriteLine(i+"是一个水仙花数");//输出i到控制台
     }
 }
 Console.ReadKey ();//等待用户按下任意键

Show results:


Summarize:

To realize the narcissus number between 100-999 through C#, the core code is to obtain the hundreds, tens and digits by taking the cosine operation %, and then calculate their cubic sum. If the result of the cubic sum is equal to the integer itself, Then the integer is a narcissus number, and the result is finally output on the console.

Guess you like

Origin blog.csdn.net/weixin_59272777/article/details/133198357