Interviews Questions, Algorithms, Aptitude, C Interview Program, C Theory Question, Aptitude Tricks, Test Series,

Sunday 28 April 2019

IOPP Program No.2.B

Program No.2.B 

Write a shell script to check whether a number is a palindrome or not.


Solution:

echo "Enter a number."
read n
p=$n
sd=0
rev=0
while [ $n -gt 0 ]
do
    sd=$(( $n % 10 ))
    rev=`expr $rev \* 10 + $sd`
    n=$(( $n / 10 ))
done
if [ $p -eq $rev ]
then
echo "Palindrome."
else
echo "Not Palindrome."
fi

0 comments:

Post a Comment