CHECKING WHETHER
THE GIVEN NUMBER IS ARMSTRONG OR NOT
To check whether the given Number is
Armstrong Number or not using Shell Programming.
ALGORITHM:
Step 1: Start
Step 2: Read the value of ‘num’
Step 3: Store the value of ‘num’ in ‘x’
and initialize the value of sum = 0.
Step 4: When the value of ‘num’ is
greater then 0, solve the following expressions
Step
5: y = num/10; z=y*y*y; sum=num+z; num=num/10
Step 6: Close the While Loop
Step 7: Check if ‘x’ is equal to ‘sum’
Step 8: Print the Result
Step 9: Stop.
SHELL PROGRAM:
echo
"Enter a Number"
read num
x=$num
sum=0
while [
$num -gt 0 ]
do
y=`expr
$num % 10`
z=`expr $y \* $y \* $y`
sum=`expr $sum + $z`
num=`expr
$num / 10`
done
if [ $x
-eq $sum ]
then
echo
"$x is an armstrong Number"
else
echo
"$x is not an armstrong Number"
fi
SAMPLE OUTPUT:
Enter a
Number
153
153 is
an armstrong Number
[Cseb19@sathish-desktop]#
sh arm.sh
Enter a
Number
123
123 is
not an armstrong Number
RESULT:
Thus the Shell Program to check
whether the given Number is Armstrong or not was executed and the output was
verified.
No comments:
Post a Comment