Virajsinh

Palindrome_3_OS_Script

Oct 8th, 2017
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. echo -n "Enter Number : "
  2. read n
  3.  
  4. # store single digit
  5. sd=0
  6.  
  7. # store number in reverse order
  8. rev=""
  9.  
  10. # store original number
  11. on=$n
  12.  
  13. while [ $n -gt 0 ]
  14. do
  15. sd=$(( $n % 10 )) # get Remainder
  16. n=$(( $n / 10 )) # get next digit
  17. # store previous number and current digit in reverse
  18. rev=$( echo ${rev}${sd} )
  19. done
  20.  
  21. if [ $on -eq $rev ];
  22. then
  23. echo "Number is palindrome"
  24. else
  25. echo "Number is NOT palindrome"
  26. fi
Add Comment
Please, Sign In to add comment