If a three-digit positive number is input through the keyboard, write a program to calculate the sum of digits.
echo "Enter a three digit number : "
read num
if [ $num -gt 999 -o $num -lt 0 ]
then
echo "Invalid number"
exit
fi
temp=$num
sum=0
while [ $num -ne 0 ]
do
r=`expr $num % 10`
sum=`expr $sum + $r`
num=`expr $num / 10`
done
echo "Sum of digits of $temp is $sum"
Shopping In MUMBAI
Are you searching for Discounts, offers, sale in Mumbai ? You are in the right place. MUMBAI, a shopping haven, has no dearth of great discounts and sales. This blog features the best MUMBAI shopping offers, sale, discounts and deals and bargains CURRENTLY GOING on in Mumbai plus a few free things thrown in on top.
Don't wait for it because once they are gone, they are gone. Hurry!..By clicking the "Like" button you will receive a daily update of discounts, sale, offers going on in Mumbai. LIKE IT.... SHARE IT...njoY.
Wednesday, January 14, 2009
Program in UNIX to calculate the sum of digits
Posted by ars at 6:39 AM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment