Because your while-loop is wrong. You need two loops, one to repeat the input of numbers and all the code to check if the number is a palindrome and another one that covers the three lines that reverses the number. Currently, you are copying the last digit of a (or n) into b, but the remaining digits are still in a. You need to continue moving digits from a to b until there are no digits left in a.
--
Mats