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
Characteristics of procedure-oriented programming: Emphasis is on doing things (algorithms). Large programs are divided into smaller programs known as functions.

PLEASE HELP ME ORACLE PROGRAMING TRIGGER

1 Triple Eigenvalue with 3 Linearly Independent Eigenvectors In this case we will have the eigenvalue l with the three linearly independent eigenvectors  ?h 1 , ?h 2 and  ?h

Expertsmind brings you unique solution in java assignments I.O streams The Java.io packages contains nearly every category you might ever need to execute feedback and resu

CSCI 3380 Project 1 For Mano’s Computer design, we have the following flowchart for fetch and decode phases: Please write the code to simulate the computer to

In this Project your task is to create a program that displays various levels of the fractal structure of the so called square shaped Sierpinski-carpet. The display of level 4 is s


1.  Use mathematical induction to prove Whenever n is a positive integer. 2.  Use loop invariant to prove that the program for computing the sum of 1,...,n is correct.

Write a Program to Show Twenty Ellipses 1. Write a program to show twenty ellipses which move away from the mouse pointer. Their initial locations should be random.

Advantages of visual basic programming language Visual Basic is an exclusive selection language published by Microsoft Company, so programs published in Visible Basic cannot, e