n
in a temporary variable tempN
.length
to 0.tempN
is not 0, divide tempN
by 10 and increment length
.length
will hold the value of k
, the number of digits in n
.tempN
to the original number n
.sum
to 0.tempN
is not 0, calculate the last digit of tempN
using tempN % 10
, raise it to the power of k
, add the result to sum
, and then remove the last digit from tempN
by dividing it by 10.sum
equals the original number n
, return true
. Otherwise, return false
.