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

Assignment Help:

  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


Related Discussions:- Shell script for a given number is armstrong number or not

Frotran 2000, Please explain about sub programming.

Please explain about sub programming.

Document type definition schema, Create a DTD which describes the structure...

Create a DTD which describes the structure of the document which you prepared in Question 1. Make sure that you use all appropriate DTD ingredients to constrain valid documents as

Assembly TASM or MASM, I need help with making a assembly program that uses...

I need help with making a assembly program that uses Hoffman''s coding scheme to compress a text file.

Explain the break statement - computer programming, Explain the Break State...

Explain the Break Statement - Computer Programming? The break statement is used as an interrupt to the normal flow of control this statement causes as exit from the switch stat

Characteristics of procedure-oriented programming, Characteristics of proce...

Characteristics of procedure-oriented programming: Emphasis is on doing things (algorithms). Large programs are divided into smaller programs known as functions.

Query a SPARQL endpoint using JENA JAVA API, program the following exercise...

program the following exercises using JAVA and JENA API: SPARQL endpoint to be queried: QUERY:">http://services.data.gov.uk/education/sparql QUERY: What are the school’s names th

Code a simulation of image compression , Your task will be to code a simula...

Your task will be to code a simulation of image compression based on the approximate low rank structure of the set of image patches. You will write functions .code = my block compr

For loop , I am trying to get right side triangle in visual logic using for...

I am trying to get right side triangle in visual logic using for loop

Create a fraction calculator program, You need to create a Fraction calcula...

You need to create a Fraction calculator program.You need to create a Fraction class to represent fraction objects and a FractionCalculator class that will perform operations on fr

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