C# Program to Check Number is Armstrong Number or Not - C# Program

C# Program to Check Number is Armstrong Number or Not

Armstrong number is a number that is equal to the sum of cubes of its digits for example 1, 153, 370, 371, 407 etc. For example 153 since 1^3 + 5^3 + 3^3 = 1+ 125 + 27 =>153

using System;
namespace ArmstrongNumberApp
{
    class Program
    {
        static void Main(string[] args)
        {
            int num,n, qsum=0,r;
            Console.Write("Enter the number :");
            num = Convert.ToInt32(Console.ReadLine());
            n = num;
            while(n!=0)
            {
                r=n%10;
                qsum =qsum+(r*r*r);
                n = n / 10;
            }
            if(qsum==num)
                Console.WriteLine("Number is Armstrong Number");
            else
                Console.WriteLine("Number is not a Armstrong Number");

            Console.ReadKey();
        }
    }
}

Output - C# Program to Check Number is Armstrong Number or Not

Enter the Number :153
Number is Armstrong Number

Enter the Number :152
Number is not a Armstrong Number

C# program to check whether a number is armstrong number or not