function sum()
{
echo "enter n"
read n
sum=0
while [ $n -gt 0 ]
do
sum=`expr $sum + $n % 10 `
n=`expr $n / 10`
done
echo -n "sum of digits:"
echo $sum
}
sum
{
echo "enter n"
read n
sum=0
while [ $n -gt 0 ]
do
sum=`expr $sum + $n % 10 `
n=`expr $n / 10`
done
echo -n "sum of digits:"
echo $sum
}
sum
OUTPUT:
enter n 231
sum of digits:6
No comments:
Post a Comment