TotalCodes
Menu
Android
Data Structure
Oracle(PL/SQL)
Shell Scripts
Monday, 27 May 2013
Shell Script to find sum of all digits
echo -n "Enter number "
read n
sd=0
sum=0
while [ $n -gt 0 ]
do
sd=$(( $n % 10 ))
n=$(( $n / 10 ))
sum=$(( $sum + $sd ))
done
echo "Sum of all digit is $sum"
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment