Sum of digits of number using shell coderinme

Sum of digits of Number

find sum of digits of number using shell
how we will calculate

Let’s code
#!/bin/bash
read -p "Enter the number: " num
sum=0
while ((num != 0))
do
b=$((num%10))
num=$((num/10))
let sum+=$b
done
echo "Sum of digits are: " $sum

sum of digits
That was all about the shell or we can say it

sum of digits of number using shell

for more about shell script
and once more

Leave a reply:

Your email address will not be published.