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

Assignment Help:

 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

 


Related Discussions:- Shell script to print count & sum of digits of given number

Write simple scripts programs , Write 3 somewhat simple scripts / programs ...

Write 3 somewhat simple scripts / programs in any language, combination of languages, and/or software. Please tell me the task you are trying to accomplish in the scripts. Idea

Assembly language program, a program that enter an alphabet from the user a...

a program that enter an alphabet from the user and compare it is vowel or not?

Shell script to count characters, Normal 0 false false fals...

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

assembly lang. H.W, 1- Allocate array with 32bit 100 element 2- Prompt the...

1- Allocate array with 32bit 100 element 2- Prompt the user to enter the maximum or the upper bound of the random value 3- Read the value and use it generate random numbers to init

JSP, can you provide some assignments for JSP learning

can you provide some assignments for JSP learning

DOM - Document Object Model, What is DOM? The Document Object Model is a pl...

What is DOM? The Document Object Model is a platform- and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure an

Pseudo code for random numbers, Pseudo code the shows logic for a program ...

Pseudo code the shows logic for a program that generates a random number, then ask the user to think of a number between 1 and 10

Lexical analyzer - xml table output, Lexical Analyzer: Symbol Table - Ho...

Lexical Analyzer: Symbol Table - Holds the symbols accepted by the lexical analyzer or parser.  Each symbol may be a terminal or a non-terminal.  Terminal symbols are listed

Abstraction hierarchy of mechanisms, Abstraction hierarchy of mechanisms ...

Abstraction hierarchy of mechanisms Given  the light-sensitive the motor and resistor,  we could  find  several  ways  of interconnecting them, using bits of ceramic and metal

Write the html code to bind this xml data, Question: (a) (i) Describe w...

Question: (a) (i) Describe what an XML Data Island is and outline the restrictions of using a Data Island. (ii) The following XML file book.xml is used to keep track of a l

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd