Google Search

Wednesday, October 27, 2010

GIVEN STRING IS PALINDROME OR NOT

To write a shell program to check whether the given string is palindrome or NOT

Algorithm:
1.Enter the input.
2. Find the length of the given string.
3.Using while ioop until the length is greater than zero do the following step 4.
4.temp = expr $11 cut — c $len
len is decremented by 1.
5.If the reverse string is equal to input string,print the given string is palindrome else not palindrome.

Program:
rev =” “
len=’expr$1 Iwc—c
while [ $len — ge 0]
do
temp=’expr$1 Icut—c$len’ len = ‘expr $ len — 1’
rev = ‘echo $rev $temp’ done
if [ $i = $rev]
then
echo “The Given string is palindrome”
else
echo “Non palindrome”
fi

Input & Output
MalayalaM
The Given string is palindrome

0 comments:

Post a Comment