Factorial,Greatest Number,String Palindrome using Shell Programming
Menu driven program for Factorial,Greatest Number,String Palindrome
a) Find factorial of a no.
b) Find greatest of three numbers
c) Find a prime no
d) Find whether a number is palindrome
e) Find whether a string is palindrome
Factorial,Greatest Number,String Palindrome Shell Programming Code
1 |
palins() <br/> { <br/> echo “ Enter a String to check for Palindrome “ <br/> read str <br/> i=1 <br/> y=`echo $str | wc -c` <br/> y=`expr $y - 1` <br/> z=$y <br/> echo “The Length of String $y” <br/> while [ $y -ne 0 ] <br/> do <br/> z=`echo $str | cut -c $i` <br/> w=`echo $str | cut -c $y` <br/> if [ "$z" != "$w" ] <br/> then <br/> echo “ The Given String $str is not Palindrome ” <br/> y=0 <br/> else <br/> i=`expr $i + 1` <br/> y=`expr $y - 1` <br/> fi <br/> done <br/> if [ "$z" = "$w" ] <br/> then <br/> echo “The Given String $str is a Palindrome” <br/> fi <br/> } <br/> palinn() <br/> { <br/> echo -n "Enter number : " <br/> read n <br/> sd=0 <br/> rev="" <br/> on=$n <br/> while [ $n -gt 0 ] <br/> do <br/> sd=$(( $n % 10 )) # get Remainder <br/> n=$(( $n / 10 )) # get next digit <br/> rev=$( echo ${rev}${sd} ) <br/> done <br/> if [ $on -eq $rev ]; <br/> then <br/> echo "Number is palindrome" <br/> else <br/> echo "Number is NOT palindrome" <br/> fi <br/> } <br/> great() <br/> { echo "enter first number" <br/> read a1 <br/> echo "enter first number" <br/> read a2 <br/> echo "enter first number" <br/> read a3 <br/> if [ $a1 -gt $a2 ] && [ $a1 -gt $a3 ]; then <br/> echo "first number $a1 is greatest" <br/> elif [ $a2 -gt $a1 ] && [ $a2 -gt $a3 ]; then <br/> echo "second number $a2 is greatest" <br/> elif [ $a3 -gt $a1 ] && [ $a3 -gt $a2 ]; then <br/> echo "third number $a3 is greatest" <br/> fi <br/> } <br/> fact() <br/> { <br/> echo "enter the number to find the factorial" <br/> read b <br/> c=1 <br/> while [ "$b" -gt 0 ]; do <br/> c=$(($c * $b)) <br/> b=$(($b-1)) <br/> done <br/> echo "factorial is $c " <br/> } <br/> clear <br/> echo "1. factorial " <br/> echo "2. greatest number " <br/> echo "3. palindrome " <br/> echo "4. palindrome string " <br/> echo "5. exit" <br/> echo "6. enter ur choice " <br/> read d <br/> case "$d" in <br/> 1) echo " factorial " <br/> fact;; <br/> 2) echo "greatest" <br/> great;; <br/> 3) echo "palindrome" <br/> palinn ;; <br/> 4) palins ;; <br/> 5) ;; <br/> * ) echo "enter right choice" <br/> esac |
Source projectgeek.com