using System;
using System.Collections.Generic;
static class Program
{
public static void Main()
{
List<int> armstrongList = Armstrong.ArmstrongEvenNumbers();
foreach (int val in armstrongList)
{
Console.WriteLine(val);
}
}
}
class Armstrong
{
public static List<int> ArmstrongEvenNumbers()
{
List<int> armstrongList = new List<int>();
for (int i = 0; i < int.MaxValue; i++)
{
int digits = 0;
double armsValue = 0;
int tempStore = i;
int tempDigits = i;
while (i > 0)
{
while (tempDigits != 0)
{
digits++;
tempDigits = tempDigits / 10;
}
int remainder = i % 10;
armsValue = armsValue + Math.Pow(remainder, digits);
i = i / 10;
}
if (armsValue == tempStore)
armstrongList.Add(tempStore);
if (armstrongList.Count == 20)
break;
i = tempStore;
}
return armstrongList;
}
}This simple program will illustrate how to calculate Armstrong number to a limit entered by users and store that in a List.