SOURCE CODE:
echo "Enter the number"
read num
sum=0
while test $num -gt 0
do
digit=`expr $num % 10`
num=`expr $num / 10`
sum=`expr $sum + $digit`
done
echo "sum of the digits= $sum"
OUTPUT:
[examuser35@localhost Jebastin]$ sh five.sh
Enter the number
12345
sum of the digits= 15
Next
« Prev Post
« Prev Post
Previous
Next Post »
Next Post »
Subscribe to:
Post Comments (Atom)
EmoticonEmoticon