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
Design the proposed implementation using the contract first approach and object oriented approaches.  At a minimum, you must provide an overview of the services in the service arch

1. Write a program that reads a minimum of three command line arguments and displays the program's results. a. Command Line arguments:  i. The first argument will be the program

how to get horizontal motion vectors field with quiver ?

.NET class libraries in .NET Whether you create value in C# or VB.NET, you are getting in touch with techniques in the same .NET category your local library. The same .NET str

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

Produce a hierarchy chart, a structured flowchart, and a Pascal program (with appropriate comments) to generate the Sales Commission Report shown below. The commission for each sal

Write a function that converts a character array to a signed floating point number. Function prototype must be as follows: int asciiToFloat( char *str, unsigned char* eflag) Follow

I have a problem which seems to be quite a rare one and I can safely say I know what exactly what is causing it. After some process of elimination I reached the conclusion that, in

How does a program provide "input" to one of its functions?