Holooly Plus Logo

Input / Question:

Input / Question:

Write a program to print all Armstrong numbers between 1 and 500. If the sum of the cubes of each digit of the number is equal to the number itself, then the number is called an Armstrong number. For example,

153 = (1 * 1 * 1) + (5 * 5 * 5) + (3 * 3 * 3).

Verified

Output/Answer

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

namespace Problem21

{

classProblem21

{

staticvoid Main(string[] args)

{

int FirstDigit, SecondDigit, LastDigit,num;

Console.WriteLine("All Armstrong Numbers Between 1 And 500.\n");

for (int i = 1; i <= 500; i++)

{

num = i;

LastDigit = num % 10;

num = num / 10;

SecondDigit = num % 10;

num = num / 10;

FirstDigit = num % 10;

if ((FirstDigit * FirstDigit * FirstDigit) + (SecondDigit * SecondDigit * SecondDigit) + (LastDigit * LastDigit * LastDigit) == i)

{

Console.WriteLine("This Is A Armstrong Number:" + i);

}

 

 

}

Console.ReadKey();

}

}

}

Output: