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 am working on a game project using C# XNA. I only have two weeks from the deadline. Would you help me to finish it up? Please let me know as soon as possible. Thanks, Sophi

Explain the Continue statement - Computer Programming? This is alike to break but is encountered less frequently. It merely works within loops where its effect is to force an imm

Calculate the total price based on several key parts required to build a state-of-the-art gaming computer. The user will have the option of selecting different parts.

Expertsmind brings you unique solution in java assignments String Handling Series signifies a sequence of character types. It has set duration of personality sequence. Onc

Expertsmind brings you unique solution in java assignments Applet In processing, and the apple company is any little application that works one specific process that works

'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

1- If the order of a (mod P) is 3, prove that the order of a+1 is 6. 2- Explain why the "simplifiled knapsack" code is not secure.

I have doubt in this section .do-while loop.could you able to clear it for me.

1. Introduction The Tube Challenge is a Guinness World Records challenge that tests both the physical and mental abilities of the person trying to break it. The main components

Identifying the Central Individual in a Social Network 1. Introduction You have just been hired by a social networking company! The division you are working in is particul