Shell script for a given number is armstrong number or not, Programming Languages

  W.A.S.S to check whether a given number is Armstrong number or not.

 

Program

 

# W.A.S.S to check that whether a given number is prime or not.

 

echo "Enter the Number:"

read num

tnum=$num

temp=0

sum=0

 

while test $num -gt 0                                   #while loop

do

   temp=`expr $num % 10`          #extract the digit by digit

   temp=`echo $temp^3 | bc`       #make the cube of digit using bc - An arbitrary

        #precision calculator

   sum=`expr $sum +  $temp`     #calculate sum of cube of all the digit

   num=`expr $num / 10`

done                                      

 

if test $sum -eq $tnum           #if the sum of cube of all the digit of given no is same as no

then

echo "Entered no $tnum is Armstrong number"

else

echo "Entered no $tnum is Not an armstrong number"

fi

 

Output

 

Enter the Number:

151

Entered no 151 is Not an armstrong number

Enter the Number:

153

Entered no 153 is Armstrong number

Posted Date: 9/26/2012 4:30:17 AM | Location : United States







Related Discussions:- Shell script for a given number is armstrong number or not, Assignment Help, Ask Question on Shell script for a given number is armstrong number or not, Get Answer, Expert's Help, Shell script for a given number is armstrong number or not Discussions

Write discussion on Shell script for a given number is armstrong number or not
Your posts are moderated
Related Questions
i have a database having field name title and comm. I want to search by name and get the all data remaining title and comm(comm is integer)

You should use the BToolkit to produce the answers to the questions below. Where applicable, please use the machine names and identifier names suggested in the question to help me

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

Task .Task 1 Database design This task will allow you to demonstrate the following Learning Outcomes (LOs): LO 2. Justify the design and development of the application and critica

(a) Write a procedure called (lookup n t). This procedure has 2 arguments: n is the value being looked up, t is the AVL tree. The subtree with n as its root is returned (or '() if

Problem 1 Explain the Booch Methodology 2 Why does every interaction diagram need a written description? Explain 3 Explain the five core workflows of the Unified Process

Question: (a) Outline the six norms to be considered before designing a Web page. (b) Write a program such that when a user right-clicks anywhere on a Web page, the follow

( Airline Reservations System ) A small airline has just purchased a computer for its new automated reservations system. You have been asked to develop the new system. You are to w

i neeed an CGI Script that send mass emails i need this input fields Sender Name: Sender Email: Subject: Message: choose (HTML Or text ) , by default HTML Emails and send bu

Create a single page that demonstrates an XHTML form. The form should include all the fields you feel are necessary for submitting an order of books and must include at least one