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
how to store an url in a dartabase(sql server 2005)? (or) create table b(url what is the datatype for url?

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

wat is- m=5; n=3; x=m++-n+++m;

A large logistics company requires a software system to support the business processes associated with managing shift patterns of employees and making the associated payments. The

Write a program that will input two numbers from the keyboard and execute each of the signed and unsigned multiply and divide instructions.  For each instruction, the program shoul

1 Real and 2 Complex Eigenvalues    From the real eigenvalue/vector pair, l 1 and ?h 1 e l1 t ?h 1 We find the other two solutions in identical manner which we did

Question 1: a) Assume that B is an array of 50 words; write a code which will place the smallest integer of array B in register AX. b) Write a small code (only three instr

showing work Ubuntu system or either opensuse

WS-Addressing, WS-Reliable Texting and WS-Security WCF tools many innovative Web solutions (WS) expectations such as WS-Addressing, WS-Reliable Texting and WS-Security. With the di

Write a program to draw the truck following figure. The program should buttons to provide When the truck runs left wheels must rotate in the correct direction. Rotating whe