Check the armstrong number enter by user using c# programing

Check the armstrong number enter by user using c# programing

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace armstrong
{
    class Program
    {
        static void Main(string[] args)
        {
            int num, sum = 0,temp,i;
            Console.WriteLine("enter the number:");
            num = Convert.ToInt32(Console.ReadLine());
            temp = num;
            while (num != 0)
            {
                i = num % 10;
                sum = sum + i * i * i;
                num = num / 10;
            }
                if(temp==sum)
                    Console.WriteLine("armstrong",sum);
                else
                {
                    Console.WriteLine("not armstrong",sum);
                }
    }
  }
OutPut :  following output Check the Nomber is armstrong or Not



       

 

Previous
Next Post »