Question - How can you check if a number is an Armstrong number or not with C#?
Answer -
using System;
public class ArmstrongDemo
{
public static void Main(string[] args)
{
int n,b,sum=0,num;
Console.Write("Enter the Number= ");
n= int.Parse(Console.ReadLine());
num=n;
while(n>0)
{
b=n%10;
sum=sum+(b*b*b);
n=n/10;
}
if(num==sum)
Console.Write("Armstrong Number.");
else
Console.Write("Not Armstrong Number.");
}
}
Output:
Enter the Number= 371
Armstrong Number.