0% found this document useful (0 votes)
4 views2 pages

Lab 6.2

Uploaded by

bayow47498
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Lab 6.2

Uploaded by

bayow47498
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

# Write a shell script to find a number is palindrome or not.

#!/bin/bash

# Function to check if a number is palindrome

is_palindrome() {

# Input number

num=$1

# Store original number to compare later

original_num=$num

reverse=0

# Loop to reverse the digits of the number

while [ $num -gt 0 ]

do

# Get the last digit

digit=$(( num % 10 ))

# Build the reverse number

reverse=$(( reverse * 10 + digit ))

# Remove the last digit from the number

num=$(( num / 10 ))

done

# Check if the original number is equal to the reversed number

if [ $reverse -eq $original_num ]; then

echo "$original_num is a palindrome number."

else

echo "$original_num is NOT a palindrome number."

fi

# Example usage

echo "Enter a number: "


read number

# Call the function with the input number

is_palindrome $number

You might also like