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
Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

'This program compares interest rates between two banks and determines the best bank 'Eric Weber, Adam Litchfield, Eric Romero, Sarah, Alex, Amy '10/5/12 'Lab #4 Problem 42 'CSC

Write a Perl program that uses a hash structure. The program should use a larger number of operations (100 or more) on this hash. To do that, use a random number generator to creat

This assignment is an individual programming assignment using Perl. It addresses objectives 3, 4, 5 and 8 as listed in the Subject Outline document. The assignment is based on them

You have been employed by a bounty hunter to create hit list (yes... you better do this right). Create a Hit List program that can records the name, bounty, and difficulty for ten

Task 1 Think about a Web site you would like to work on for Assignment 2. For example, you can do a personal interest site, a site for your favourite nonprofit organization,

Complete the following program to move a value of 0xFFH to PORTB LIST p=18f4550 #include org 0x0000 movlw 0x00 _________ movlw 0xFF movwf PORTB end .

Windows XP using C# load a binary file and send it thru a USB port to the USB port of STM32. STM32 received the file and then write it into an I2C EEPROM.

Hi, Can you do exercises: D2, D3, D4, and D5 on page 230 of the following book: http://www.daimi.au.dk/~bra8130/Wiley_book/wiley.html . The book can be downloaded for free from t

1)      Go to Start -> Programs->Accessories->Notepad. 2)      Start with a document type tag & an opening tag. Enter the given line in your doc.