Friday, February 17, 2012

Shell Programming - Sum of Individual Digits


MC9227 - System Software Lab 

Practical Program - 6

Shell Programming - Sum of Individual Digits 

[rmurali@AntiViruS ~/SS]$ cat > shell1.sh
clear
echo "Practical Program 6 : Shell Programming"
echo;
echo "Sum of Individual Digits"
echo;
echo "Enter a number "
read n
sum=0
sd=0
while [ $n -gt 0 ]
do
 sd=`expr $n % 10`
 sum=`expr $sum + $sd`
 n=`expr $n / 10`
done
 echo "Sum of digit For number is $sum"
echo;
echo "End of Shell Program1"

[rmurali@AntiViruS ~/SS]$ sh shell1.sh
Practical Program 6 : Shell Programming

Sum of Individual Digits

Enter a number
434
Sum of digit For number is 11

End of Shell Program1
[rmurali@AntiViruS ~/SS]$

No comments:

Post a Comment