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


Expert's answer

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
LATEST TUTORIALS
APPROVED BY CLIENTS