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

What is cisc & risc?, Question 1 What is CISC & RISC? Explain their addres...

Question 1 What is CISC & RISC? Explain their addressing modes Question 2 Discuss the following- Design Specification of Assembler Design of Single Pass Assembler

Discuss about wap architecture, Question 1 How to call a WML Script from a...

Question 1 How to call a WML Script from a WML Page? Question 2 Write short notes on WML Script Operators and Expressions Question 3 Write short notes on WML Script Statements

How do you find the complexity of an algorithm, How do you get the complexi...

How do you get the complexity of an algorithm? What is the relation b/w the time & space complexities of an algorithm? Justify your answer with an example.

Introduction to c#, All programs have to be done in console application. Pr...

All programs have to be done in console application. Program 1, 2 and 3 are due on 2/11/12 Program 4, 5, and 6 are due on 2/18/12 Program 7, 8, and 9 are due on 2/25/12 Program 10

X86 Assembly, You are to Use ASCII operations to design an IA-32 assembly ...

You are to Use ASCII operations to design an IA-32 assembly language program which will do addition and subtraction on positive integers of any length represented in characters. T

Programming assignment, The fancy new French restaurant La Food is very p...

The fancy new French restaurant La Food is very popular for its authentic cuisine and high prices. This restaurant does not take reservations. To help improve the efficiency of t

Write a program to draw the fish, Write a program to draw the figure shown ...

Write a program to draw the figure shown below. the program must provide: a. Close the fish's mouth slowly (at least 5 moves from the original position to close the mouth) b.

shell script to check that a given number is prime or not, Normal 0 ...

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

Risk - controls and audit tests, Internal Audit has been asked by the State...

Internal Audit has been asked by the State to review the activities of  The Commission on Workforce Development. The Commission was established several years ago by the state legis

What are relative urls, What are Relative URLS ? When a web browser re...

What are Relative URLS ? When a web browser reads an HTML document, it has a great deal of information about the document. This includes the protocol used to retrieve the docu

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