LINUX SEHLL PROGRAM FOR PERFORMING PALINDROME CHECKING | WHETHER THE GIVEN STRING IS PALINDROME OR NOT | OPERATING SYSTEM (OS) LAB IN LINUX ENVIRONME

AIM:
To write a shell program for checking whether the given string is palindrome or not.
ALGORITHM:
· Get the given string.
· Reverse the string.
· Compare the given string with reversed string if they are equal print “palindrome” otherwise “not palindrome”.

PROGRAM SOURCE CODE
echo ”enter the string”
read a
r=$a
len=`expr length $a`
c=1
f=” “
while [ $c – le $len ]
do
e= `expr substr $a $c1 `
f=$e$f
c=`expr $c + 1`
done
echo “the reversed string is $f”
if [ $r=$f ]
then
echo “the given string is palindrome”
else
echo “the given string is not palindrome”
fi

CONCLUSION:
Thus the shell program to check palindrome or not are written and executed successfully

Post a Comment

0 Comments