As the number is a palindrome , the same swap of digits should be performed in the 2 nd half of ' num '
temp = num [ n - i - 1 ] ; num [ n - i - 1 ] = num [ n - smallest - 1 ] ; num [ n - smallest - 1 ] = temp ;