Logo 
Search:

Unix / Linux / Ubuntu Articles

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

Program to calculate the sum of its digits

Posted By: Adelheide Fischer     Category: Unix / Linux / Ubuntu     Views: 12310

If a five digit number is input through the keyboard, write a program to calculate the sum of its digits.

Code for Program to calculate the sum of its digits in Unix / Linux / Ubuntu

echo "Enter five digit number "
read no
total=0
while [ $no -ne 0 ]
do
        temp=`echo $no % 10 | bc`
        total=`echo $total + $temp | bc`
        no=`echo $no / 10 | bc`
done
echo "Total of digit is : $total"
  
Share: 


Didn't find what you were looking for? Find more on Program to calculate the sum of its digits Or get search suggestion and latest updates.

Adelheide Fischer
Adelheide Fischer author of Program to calculate the sum of its digits is from Frankfurt, Germany.
 
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!