Armstrong number is a number that is equal to the sum of cubes of its digits.
For example:
153, 1634 is armstrong number. because 13+53+33=153
153=1*1*1+5*5*5+3*3*3 for 3 digits
14+64+34+44=1634 for four digit
In this example, you will learn whether the input enter by the user is Armstrong number or not in the C# program.
using System;
class Armstrong{
public static void Main() {
int sum=0,copy,n,r;
Console.Write("Enter the number: ");
n=int.Parse(Console.ReadLine());
copy=n;
while(copy>0)
{
r=copy%10;
sum=sum+(r*r*r);
copy=copy/10;
}
if(sum==n)
Console.WriteLine(n+" is armstrong number");
else
Console.WriteLine(n+" is not armstrong number");
}
}
Enter the number: 153 153 is armstrong number
Enter the number: 123 123 is not armstrong number