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
wat is- m=5; n=3; x=m++-n+++m;

#questiWrite down different system calls for performing different kinds of tasks.on..

Class a Abstract Data Type: is a template for creating objects. A class describes a collection of related objects i.e. instances of the classes. Basically classes are user-defined

Applications of OOP, The promising areas for application of OOP include: Real-time systems Simulation and modelling Object-oriented databases Hypertext, hype

Define an Example of Switch Statement? estimate(number) int number; /* Estimate a number as none, one, two, several, many */ {       switch(number) { case 0 :

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

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

Each of the following two procedures defines a method for adding two positive integers in  terms of the procedures inc, which increments its argument by 1, and dec, which decrement

Difference between java and j2ee programming In the basic form, the phrase java is placed as a selection terminology. On the other hand, the phrase J2EE is placed as a renderin

Vacation Envy - Travel and Photo Sharing Website Site Overview- Vacation Envy is a travel as well as photo-sharing site. Make your travel map, share photos and show off al