Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

narcissistic

public static bool IsNarcissistic(int number)
{
  var sum = 0;
  var temp = number;
  var numberOfDigits = 0;
  while (temp != 0)
  {
    numberOfDigits++;
    temp /= 10;
  }

  temp = number;
  while (number > 0)
  {
    var remainder = number % 10;
    var power = (int)Math.Pow(remainder, numberOfDigits);

    sum += power;
    number /= 10;
  }

  return sum == temp;
}
 
PREVIOUS NEXT
Tagged: #narcissistic
ADD COMMENT
Topic
Name
8+8 =