Ruby program to check whether the given number is Armstrong

This Ruby example will check given number is Armstrong or not

 

puts "Enter the number"
num=gets.chomp.to_i

temp=num
sum = 0

while num!=0  #implementation of while loop
    rem=num%10
    num=num/10
    sum=sum+rem*rem*rem
end

if(temp==sum)
    puts "The #{temp} is Armstrong"
else
    puts "The #{temp} is not Armstrong"
end

 

Output

Enter the number
 153
The 153 is Armstrong