SHELL PROGRAM
Write a program to find sum of a digit ? | Shell Program |
#!/bin/bash
echo "Enter a number"
read n
g=$n
s=0
while [ $n -gt 0 ]
do
k=$(($n%10))
n=$(($n/10))
s=$(($s+$k))
done
echo "sum of digits of $g is:$s"
OUTPUT
Enter a number
123
sum of digits of 123 is:6
echo "Enter a number"
read n
g=$n
s=0
while [ $n -gt 0 ]
do
k=$(($n%10))
n=$(($n/10))
s=$(($s+$k))
done
echo "sum of digits of $g is:$s"
OUTPUT
Enter a number
123
sum of digits of 123 is:6
Post a Comment
0 Comments