#
# Accept number and check the number is even or odd, finds the length of the number, sum of the digits
# in the number.
#
clear
echo -n "Enter any number :"
read number
echo "===== Available choices ====="
echo "1. Odd or even"
echo "2. Find length of number"
echo "3. Sum of digits of number"
echo "E. Exit"
echo "============================="
echo -n "\nEnter your choice:"
read choice
while [ $choice != 'E' -o $choice != 'e' ]
do
case $choice in
1)
if [ `expr $number % 2` -eq 0 ]
then
echo "Number is even"
else
echo "Number is odd"
fi
;;
2)
length=$((`echo $number | wc -c` - 1))
echo "Length of number is "$length
;;
3)
tempnumber=$number
sum=0
while [ $tempnumber -gt 0 ]
do
digit=`expr $tempnumber % 10`
sum=`expr $sum + $digit`
tempnumber=`expr $tempnumber / 10`
done
echo "Sum of digit of a number is "$sum
;;
[eE])
exit;
;;
*)
echo "Invalid choice"
;;
esac
read temp #for pause
clear
echo "Number you entred : "$number"\n"
echo "===== Available choices ====="
echo "1. Odd or even"
echo "2. Find length of number"
echo "3. Sum of digits of number"
echo "E. Exit"
echo "============================="
echo -n "\nEnter your choice:"
read choice
done