Find Sum Of Five Digit Number In the basic shell programming in Linux UNIX script programming

These program find out the sum of the five digit number using while loop, it uses the modulo division operator, and division operator to perform these program.
Source code bash shell Programming Algorithm
echo "Enter the number"
read num
sum=0
while test $num -gt 0
do
digit=`expr $num % 10`
num=`expr $num / 10`
sum=`expr $sum + $digit`
done
echo "sum of the digits= $sum"

OUPUT CS1252 Operating Systems lap
[redhat33@localhost jana]$ sh five.sh
Enter the number
12345
sum of the digits= 15

Post a Comment

0 Comments