Program to Check Armstrong Number

By | March 8, 2018

Here, we will Check Whether the entered number is an Armstrong Number or Not.

An Armstrong number is a number such that the sum of its digits raised to the third power is equal to the number itself. For example, 371 is an Armstrong number, since  3**3 + 7**3 + 1**3 = 371.

using System;

namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int number, remainder, sum = 0;
Console.Write("Enter the Number: ");
number = int.Parse(Console.ReadLine());
for (int i = number; i > 0; i = i / 10)
{
remainder = i % 10;
sum = sum + remainder * remainder * remainder;

}
if (sum == number)
{
Console.Write("Entered Number is an Armstrong Number");
}
else
Console.Write("Entered Number is not an Armstrong Number");
Console.ReadLine();
}
}
}

Output:

 

Like it? Share it