C# - Find Armstrong Number
An I have given here the program for finding armstrong number of a three digits number.
The condition for armstrong number is,
Sum of the cubes of its digits must equal to the number itself.
For example, 407 is given as input.
4 * 4 * 4 + 0 * 0 * 0 + 7 * 7 * 7 = 407 is an armstrong number.
Source Code
using System;
using System.Collections.Generic;
using System.Text;
namespace Armstrong
{
class ArmstrongNumber
{
static void Main(string[] args)
{
System.Console.WriteLine("List of Armstrong Numbers between (100 - 999):");
for(int i = 100; i <= 999; i++)
{
int a = i / 100;
int b = (i - a * 100) / 10;
int c = (i - a * 100 - b * 10);
int d = a*a*a + b*b*b + c*c*c;
if(i == d)
System.Console.WriteLine("{0}", i);
}
}
}
}
Output
List of Armstrong Numbers between (100 - 999):
153
370
371
407
|