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
Project2: A Simple Distributed Computing Platform (Due at 11:59:59pm on 04/12/2012 (EST)) Description: You are asked to develop a replicator (client) that distributes a large job

Write a function named prob2.m which creates and returns an N×N identity matrix. An identity matrix is a square matrix with values of one on the main diagonal and zeros in all off-

Determine the address accessed by each of the following instruction if DS=1100H, BX=0200H, LIST=0250H AND SI=0500H-: 1) MOV LIST[SI],EDX?0250+0500+11000=11750 2

W.A.S.S to display all the files in a specified directory in the following format: File  size in K        Date   Protection    Owner Program echo -e "Enter dir : \c" read di

write c++ source code to find the number of digits in a given integer? pls ans

how do I change a existing formula with a new formula and it show the result

Type of Linear Programming - DEA The Express Dry Cleaners currently has four locations in the Chicago area and willing be opening the fifth in the very near future.  Mr. James,

XML Publishing. Consider the following relational data: Products: pid Name Price Description 323 gizmo

The GuessingGame class contains a skeleton for a program to play a guessing game with the user. The program should randomly generate an integer between 1 and 10 and then ask the us

Question: (i) All Security authentication mechanism that run on the TRU64 Unix Operating system run under the Security Integration Architecture (SIA ) layer. Explain with di