Code.GeekInterview.com
 
Code Samples UNIX
 

UNIX Shell Program To Find Palindrome


Code ResourceAuthor: mano.mithun  

Difficulty Level: Beginner

Published: 3rd Aug 2010   Read: 6750 times  

Filed in: UNIX
Add Comment


 

 

Sponsored Links


 

 

To find a palindrome of a number using shell programming!

 


Sample Code
  1. echo "String please :"
  2. read str
  3. len=`expr $str | wc -c`
  4. len=`expr $len - 1`
  5. mid=`expr $len / 2`
  6. flag=1
  7. m=1
  8. while [ $m -le $mid ]
  9. do
  10.         c=`echo $str | cut -c$len`
  11.         p=`echo $str | cut -c$m`
  12.         if [ $c != $p ]
  13.         then
  14.            flag=0
  15.            break
  16.         fi
  17.         m=`expr $m + 1`
  18.         len=`expr $len - 1`
  19. done
  20. if [ $flag -eq 1 ]
  21. then
  22.    echo "The string is palindrome"
  23. else
  24.    echo "The string is not palindrome"
  25. fi
Copyright GeekInterview.com


Next Article: File Retriever


 

Latest Code Samples

 

Popular Code Samples

 

Related Code Samples

 

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    



Popular Coders

# Coder NameHits
1. mano.mithun6751
2. christia3583
3. GregMark2948

Active Coders

# Coder NameCodes
1. GregMark1
2. christia1
3. mano.mithun1

Refined Tags