Structure Query Language, C programming, Java, Servlet, Jsp, Unix

Wednesday, 22 February 2012

Accept number and check the number is even or odd, finds the length of the number, sum of the digits in the number.


echo "Enter number:"
read no;
count=0
total=0
while [ $no -ne 0 ]
do
a=`expr $no % 10`
no=`expr $no / 10`
total=`expr $total + $a`
count=`expr $count + 1`
done
if [ `expr $no % 2` -eq 0  ]; then
echo "NUMBER IS EVEN"
else
echo "NUMBER IS ODD"
fi
echo "SUM OF ALL DIGITS:$total"
echo "TOTAL NUMBER OF DIGIT:$count"

1 comment:

  1. pleas Display value of $no
    before if condition
    And Let Me Know The Answer.

    ReplyDelete