The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Palli
By Guest on 27th March 2024 08:32:57 AM | Syntax: PYTHON | Views: 81



New Paste New paste | Download Paste Download | Toggle Line Numbers Show/Hide line no. | Copy Paste Copy text to clipboard
  1.  
  2.     #!/bin/bash
  3.      
  4.     # Read the number from user input
  5.     echo "Enter a number: "
  6.     read num
  7.      
  8.     # Initialize an empty variable to store the reversed number
  9.     rev=0
  10.      
  11.     # Store the original number
  12.     on=$num
  13.      
  14.     # Reverse the number
  15.     while [ $num -gt 0 ]
  16.     do
  17.         # Get the last digit
  18.         k=$(($num % 10))
  19.      
  20.         # Reverse the number by adding the last digit to the right
  21.         # of the reversed number
  22.         rev=$(($rev * 10 + $k))
  23.      
  24.         # Remove the last digit from the number
  25.         num=$(($num / 10))
  26.     done
  27.      
  28.     # Check if the original number and the reversed number are the same
  29.     if [ $on -eq $rev ]
  30.     then
  31.         echo "The number is a palindrome."
  32.     else
  33.         echo "The number is not a palindrome."
  34.     fi





palli