Armstrong Numberalgorithm

Source

ARMSTRONG NUMBER

The program takes a number and checks if it is an Armstrong number.

An n-digit number such that the sum of each digit raised to the power n is the number itself,

is an Armstrong number.

  • an armstrong number example : 153

Review

  • SmartContract
function armstrong(uint num) internal pure returns (bool result) {
    uint tmp = num;
    uint cach;
    uint sum = 0;
    while(tmp != 0){
        cach = tmp % 10;
        sum = sum + cach * cach * cach;
        tmp = tmp / 10;
    }
    sum == num ? result = true : result = false; // short if
}