Logo 
Search:

Unix / Linux / Ubuntu Articles

Submit Article
Home » Articles » Unix / Linux / Ubuntu » Homework HelpRSS Feeds

Write a shell script to find sum of digits of a number

Posted By: Chloe Brown     Category: Unix / Linux / Ubuntu     Views: 30389

Write a shell script to find sum of digits of a number.

Code for Write a shell script to find sum of digits of a number in Unix / Linux / Ubuntu

echo -n "Input no : "
read no

length=`expr length $no`

while [ $length -ne 0 ]
do
    b=`expr substr $no $length 1`
    ans=`expr $ans + $b`    
    length=`expr $length - 1`
done
echo "Sum of Digit is : $ans"
  
Share: 


Didn't find what you were looking for? Find more on Write a shell script to find sum of digits of a number Or get search suggestion and latest updates.

Chloe Brown
Chloe Brown author of Write a shell script to find sum of digits of a number is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!