Pages

Men

rh

6/10/2012

Finding Number is Amstrong or not?


Protected void  ChkNuymArmStrongornot()
{
     int number, _num, sum = 0;
     Console.WriteLine("Enter a Number");
    number = Convert.ToInt32(Console.ReadLine()); 
      for (int i = number; i > 0; i = i / 10)
     {
_num = i % 10;  
         sum = sum + _num * _num * _num;     }

     if (sum == number)
    {
        Console.WriteLine("The Number is Armstrong Number");
    }
    else
   {
       Console.WriteLine("The Number is not Armstrong Number");
   }
}




           
         

No comments :

Post a Comment