Answer to Question #294053 in Algorithms for Moon

Question #294053

Write an algorithm to check whether a given number is an Armstrong number. An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 33 +73 + 13 = 371


1
Expert's answer
2022-02-08T09:35:43-0500
Start
   Declare Real sum = 0
   Declare Integer remainder 
   Declare Integer tempNumber
   Declare Integer number
   Display 'Enter a three-digit positive integer: '
   Set tempNumber = number
   while tempNumber > 0 do
      Set remainder = tempNumber % 10
      Set sum =sum + remainder * remainder * remainder
      Set tempNumber = parseInt(tempNumber / 10)
   End while
   if sum == number then
      Display number, ' is an Armstrong number' 
   else 
      Display number, ' is NOT an Armstrong number' 
   End if
Stop

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS