Tuesday, April 19, 2016

Check the number is Armstrong or not



What is Armstrong Number

An Armstrong Number is the number which is equal to the sum of each digit raised to the Nth power.

Example :  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication9
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, rem, sum = 0;
            Console.Write("enter the number");
            n = Int32.Parse(Console.ReadLine());
            for(int i=n;i>0;i=1/10)
            {
                rem=i%10;
                sum=sum+rem*rem*rem;
            }
            if(sum==n)
            {
                Console.Write("Number is armstrong");
            }
            else
            {
                Console.Write("number is not armstrong");
                Console.ReadLine();
            }

        }
    }
}
 

No comments:

Post a Comment