≡ Menu

Armstrong Number

A positive integer is called an Armstrong number of order n if:


Source Code: Check Armstrong number

Here, we ask the user for a number and check if it is an Armstrong number.

We need to calculate the sum of the n-power of each digit. So, we initialize the sum to 0 and obtain each digit number by using the modulus operator %. The remainder of a number when it is divided by 10 is the last digit of that number. We take the n-power using exponent ** operator.

Finally, we compare the sum with the original number and conclude that it is Armstrong number if they are equal.

{ 0 comments… add one }


Next post:

Previous post:

%d blogger hanno fatto clic su Mi Piace per questo: