C# Program to Check Weather The Given Number is Armstrong Number or Not

Armstrong number is a number that is equal to the sum of cubes of its digits.

For example 0, 1, 153, 370 and 371 are the Armstrong numbers.


Let's try to understand How the Armstrong number is calculated.

371 = (3*3*3)+(7*7*7)+(1*1*1) =27+343+1=371         


Let's understand the C# program to check Armstrong Number.


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Collections;

using System.Threading;

using System.IO;



namespace CSharpProgram

{

    class AkbTechie

     {

            static void Main(string[] args)

           {

                   int  Num,r,sum=0,temp;      

                   Console.Write("Enter the Number : ");

                   Num = int.Parse(Console.ReadLine());

                   temp = Num;

                   while (Num > 0)      

                   {

                    r = Num % 10;      

                    sum=sum+(r*r*r);

                    Num = Num / 10;      

                   }

                   if (temp == sum)

                   {

                       Console.Write("Entered Number is Armstrong Number.");

                   }

                   else

                   {

                       Console.Write("Entered Number is Not Armstrong Number.");

                   }

                   

               Console.ReadKey(); 

          }

    }

}


Output:-

Enter the Number : 153

Entered Number is Armstrong Number.


एक टिप्पणी भेजें

0 टिप्पणियाँ