C# program to print the Armstrong numbers
Program.cs
int num, r, sum, temp, ul;
Console.WriteLine("———————————————————————————————————————————");
Console.WriteLine("Program to print the Armstrong numbers");
Console.WriteLine("———————————————————————————————————————————");
Console.Write("Enter the upper limit range ");
ul = Convert.ToInt32(Console.ReadLine());
Console.Write("\nArmstrong numbers are\n");
for (num = 1; num <= ul; num++)
{
    temp = num;
    sum = 0;
    while (temp != 0)
    {
        r = temp % 10;
        temp = temp / 10;
        sum = sum + (r * r * r);
    }
    if (sum == num)
    {
        Console.WriteLine("{0} ", num);
    }
}
Console.WriteLine("———————————————————————————————————————————");
Output
kodingwindow@kw:~/csharp$ dotnet run
———————————————————————————————————————————
Program to print the Armstrong numbers
———————————————————————————————————————————
Enter the upper limit range 1000

Armstrong numbers are
1 
153 
370 
371 
407 
———————————————————————————————————————————
kodingwindow@kw:~/csharp$ 
What Next?
C# Strings
Advertisement