We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Friday, June 19, 2015

Check an Armstrong number is or not?

class Program
    {
        static void Main(string[] args)
        {
            int sum = 0, i, r;
            Console.WriteLine("Enter the number");
            int n = int.Parse(Console.ReadLine());
            for (i = n; i > 0; i = i / 10)
            {
                r = i % 10;
                sum = sum + r * r * r;
            }
            if (n == sum)
            {
                Console.WriteLine("This is Armstrong number");
            }
            else
            {
                Console.WriteLine("This is not Armstrong number");
            }
            Console.WriteLine();
            Console.ReadLine();
        }

    }

OUTPUT:

Enter the number: 153
This is Armstrong number

No comments: