Shell script to print count & sum of digits of given number, Programming Languages

 W.A.S.S to print the count and sum of digits of a given number.

 

Program

 

   # W.A.S.S to print the count and sum of digits of a given number.

 

echo "Enter the Number:"

read num

temp=0

sum=0

cnt=0

 

while test $num -gt 0

do

   temp=`expr $num % 10`          #extract the digit from nuber

   sum=`expr $sum +  $temp`      #add the digit into sum

   num=`expr $num / 10`             #reduce no by dividing the no by 10

   cnt=`expr $cnt + 1`                  #conter to count  the no of digit

done

 

echo "Total No of digit in the give no is $cnt"

echo "Sum of digit:$sum"

 

 

Output

 

Enter the Number:

786

Total No of digit in the give no is 3

Sum of digit:21

 

Posted Date: 9/26/2012 4:45:41 AM | Location : United States







Related Discussions:- Shell script to print count & sum of digits of given number, Assignment Help, Ask Question on Shell script to print count & sum of digits of given number, Get Answer, Expert's Help, Shell script to print count & sum of digits of given number Discussions

Write discussion on Shell script to print count & sum of digits of given number
Your posts are moderated
Related Questions
UNIX Operating System 1. Explain all the layers present in a UNIX Architecture? List and explain each of them. 2. Describe the term Inter-Process Communication. What are var

I need a program that writes the first column of the matrix. The numbers in this column follow the pattern below: 1. Numbers start at 1 and count up to ''nels'' in increments of

Shemrock Inc. is a brake pad manufacturing company. This company uses raw materials, such as carbon powder, iron, ash, and resin. It wants to develop an inventory management system

Area Under Curve Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve be

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

We need help for build a Price Quote Generator I am interested in two things (A) a web based system that will allow a user to enter the parameters of their contests (there are o

W.A.S.S to display all the files in a specified directory in the following format: File  size in K        Date   Protection    Owner Program echo -e "Enter dir : \c" read di

how do I get my actor to spin


SailDublin Ferry provides ferries to mainland Britain, Europe and America. Having observed the success of Irish ferries and Stennaline online booking system; SailDublin ferry has d