Wednesday 28 September 2011


GENERATING ARMSTRONG NUMBERS

Aim:

To write a shell program to print the Armstrong numbers between the given limit.

Algorithm:
1. Start the program.
2. Get the boundary value from the user.
3. Initialize i = 1.
4. If i n then assign number = i.
5. If i not equal to number then separate the digits of the number by dividing the number by 10.
6. The remainder value is cubed and it is added to the sum value.
7. Change the number = number I 10.
8. Repeat steps 5 to 7.
9. Check the number and the summed value. If both are same then that number is an Armstrong number.
10. Increment the i value by 1.
11. Repeat steps4to 10.
12. Stop the program.

Program:
#Armstrong Number Generation
echo “Enter the boundary”
read n
jt 1
while test $i —ne $no
do
flag = 0
no = $i
while test $i —ne 30
do
r =‘expr$i%10’
flag = ‘expr $flag + $r ““ $r “K” $r’
i=’expr$iI 10
do
if test $flag —eq $no
then
echo “is an Armstrong Number”
fi
sf0
 ‘expr$i+l’ done

  Output
Enter the boundary
200
1 is an Armstrong number
153 is an Armstrong number.

Result
Thus the program is written and executed for displaying Armstrong numbers
between the given limits.

0 comments:

Post a Comment