Ruby program to check whether the given number is palindrome

In this Ruby Example by using while loop we are checking the given number is Palindrome 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*10+rem
end

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

 

Output 

First Run

Enter the number
 123
The 123 is not a palindrome

 

Second Run

Enter the number
 121
The 121 is a palindrome