Showing posts with label armstrong number. Show all posts
Showing posts with label armstrong number. Show all posts

Sunday, March 22, 2015

Armstrong Number

Algorithm
Step 1 : Start
Step 2 : Read number
Step 3 : Initialize 0 to sum and number to num
Step 4 : Extract lastdigit by computing number modulo 10
Step 5 : Cube the lastdigit and add it to sum
Step 6 : Divide number by 10
Step 7: Repeat steps 4–6 until number > 0
Step 8 : If sum = number then
Print “Armstrong number”
Step 8.1 : else
Print “Not an Armstrong number”
Step 9 : Stop

Program (armstrong.sh)
# Armstrong number using while loop
echo -n "Enter a number : "
read n
a=$n
s=0
while [ $n -gt 0 ]

Saturday, January 11, 2014

PROGRAM TO DETERMINE THE GIVEN NUMBER IS ARMSTRONG OR NOT

echo "Enter the no"
read n
i=0
k=$n
while test $n -ne 0
do
u=`expr $n % 10`
i=`expr $i + $u \* $u \* $u`
n=`expr $n \/ 10`
done
if test $k -eq $i
then
echo "$k is a armstrong number"
else
echo "$k is not armstrong number"
fi
~
~
"arm" 16L, 225C                                               15,1          All

Output:

"arm" 16L, 225C written
[eceb33@linuxserver eceb33]$ sh arm
Enter the no
153

153 is a armstrong number