Computer Science, asked by Shibbu7061, 10 months ago

How to do Armstrong number calculation in Python without the usage of any function?

Answers

Answered by imkaifkhan20
1

(1)    User has to enter any number

(2)   Counting the Number of individual digits (For Example, 370 means 3)

(3)   Divide the given number into individual digits (For Example, Divide 370    into      3, 7 and 0)

(4)   Calculate the power of n for each individual and add those numbers

(5)   Compare original value with Sum value.

(6)   If they exactly matched then it is Armstrong number else it is not Armstrong

using while loop:

# Python Program For Armstrong Number using While Loop

Number = int(input("\nPlease Enter the Number to Check for Armstrong: "))

# Initializing Sum and Number of Digits

Sum = 0

Times = 0

         

# Calculating Number of individual digits

Temp = Number

while Temp > 0:

          Times = Times + 1

          Temp = Temp // 10

# Finding Armstrong Number

Temp = Number

while Temp > 0:

          Reminder = Temp % 10

          Sum = Sum + (Reminder ** Times)

          Temp //= 10

if Number == Sum:

          print("\n %d is Armstrong Number.\n" %Number)

else:

          print("\n %d is Not a Armstrong Number.\n" %Number)

Similar questions