GIVEN STRING IS PALINDROME OR NOT
Aim:
To write a shell program to check whether the given string is palindrome or
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.
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]
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]
rev = ‘echo $rev $temp’ done
if [ $i = $rev]
then
echo “The Given string is palindrome”
echo “The Given string is palindrome”
else
echo “Non palindrome”
fi
Input & Output
MalayalaM
The Given string is palindrome
The Given string is palindrome
Result:
Thus the program is written and executed to check the given string is
palindrome or not.
palindrome or not.
0 comments:
Post a Comment