Sunday 20 April 2014

Check wheather given number is Armstrong or not


Write a program in c# (c sharp) to  Check whether given number is Armstrong or not .

using System;

namespace ArmStrongNumber
{

    class Program
    {
        static void Main(string[] args)
        {           
             int num, temp, sum, d1;
            Console.WriteLine("Enter a number");
            num = Convert.ToInt32(Console.ReadLine());
            sum = 0;
            temp = num;
            while (Convert.ToBoolean(num))
            {
                d1 = num % 10;
                num = num / 10;
                sum = sum + (d1 * d1 * d1);
            }

            if (sum == temp)
            {
                Console.WriteLine(" Entered numeber is an armstrong number..!");
            }
            else
            {
                Console.WriteLine(" Entered number is not an armstrong number..!");
            }
            Console.ReadKey();
        }
    }
}

If anyone have any doubt about the program , please comment and you can also mail me on "ibsarmschauhan13@gmail.com" and "makansingh42@yahoo.com".


No comments:

Post a Comment