Python Compiler
import math num = 19; copyNum = num; digits = 0; remainder = 0; total = 0; #find number of digits in num variable while(copyNum != 0): digits += 1; copyNum = math.floor(copyNum / 10); copyNum = num; #slice the numbers from last digits while(copyNum != 0): remainder = copyNum % 10 total += pow(remainder, digits) copyNum = math.floor(copyNum / 10) #result if(num == total): print("%d is an armstrong number" % num); else: print("%d is not an armstrong number" % num);
OUTPUT
19 is not an armstrong number
×

Save as Private