Given a number num, find whether the given number is palindrome or not using Bash Scripting.
Examples:
Input : 666 Output : Number is palindrome Input : 45667 Output : Number is NOT palindrome
Approach
To find the given number is palindrome just check if the number is same from beginning and the end. Reverse the number to check if the number reversed is equal to the original number or not, if yes than echo Number is palindrome otherwise echo Number is NOT palindrome .
BASH
num=545 # Storing the remainder s=0 # Store number in reverse # order rev="" # Store original number # in another variable temp=$num while [ $num -gt 0 ] do # Get Remainder s=$(( $num % 10 )) # Get next digit num=$(( $num / 10 )) # Store previous number and # current digit in reverse rev=$( echo ${rev}${s} ) done if [ $temp -eq $rev ]; then echo "Number is palindrome"else echo "Number is NOT palindrome"fi |
Output:
Number is palindrome
Recommended Posts:
- Bash program to check if the Number is a Prime or not
- Program to check the number is Palindrome or not
- Recursive program to check if number is palindrome or not
- C Program to Check if a Given String is Palindrome
- Program to check if an Array is Palindrome or not
- Program to check if an Array is Palindrome or not using STL in C++
- Program to check if an array is palindrome or not using Recursion
- Java program to check whether a string is a Palindrome
- TCP Client-Server Program to Check if a Given String is Palindrome
- Python program to check if given string is vowel Palindrome
- Java program to check palindrome (using library methods)
- Check if a number is Palindrome in PL/SQL
- Check if a number is Palindrome
- Check if number is palindrome or not in Octal
- Generate number with given operation and check if it is palindrome
- Check whether the given floating point number is a palindrome
- To check a number is palindrome or not without using any extra space
- Check if a number with even number of digits is palindrome or not
- Check if actual binary representation of a number is palindrome
- Bash program to find A to the power B
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : AnmolAgarwal

