Print out all the Narcissus numbers between 100-999

Time:2020-1-14

Title: print out all the “narcissus number” between 100-999. The so-called “narcissus number” refers to a three digit number whose cubic sum of each digit is equal to the number itself. For example, 153 is a “narcissus number”, because the third power of 153 = 1 + 5 + 3.
1. Program analysis: use for loop to control 100-999 numbers. Each number is decomposed into bits, tens and hundreds.

class Program
    {
        static void Main(string[] args)
        {
            for (int num = 100; num <= 999; num++)
            {
                Int i = num% 10; // take a bit
                Int j = (Num / 10)% 10; // take the tens
                Int k = num / 100; // take the hundreds
                if(i*i*i+j*j*j+k*k*k==num)
                {
                    Console.WriteLine(num);
                }
            }
            Console.ReadKey();
        }
    }

  

Recommended Today

RCAST 35: add type to currency

– font ALT: Simsun; MSO font charset: 134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} @font-face {font-family:”Cambria Math”; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:Calibri; Variable; Ose-1: 216301111; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 680460288 22 0 262145 0;} /\* Style […]