#!/bin/bash

# SCRIPT: armstrong_bw_range.sh

# USAGE: armstrong_bw_range.sh

# PURPOSE: Finding Armstrong numbers between given range.

# \\\\ ////

# \\ - - //

# @ @

# ---oOOo-( )-oOOo---

#Armstrong numbers are the sum of their own digits to the power of

#the number of digits. As that is a slightly brief wording, let me

#give an example:

#153 = 1³ + 5³ + 3³

#Each digit is raised to the power three because 153 has three

#digits. They are totalled and we get the original number again!

#Notice that Armstrong numbers are base dependent,but we'll mainly be

#dealing with base 10 examples.The Armstrong numbers up to 5 digits

#are 1 to 9,153, 370, 371, 407, 1634, 8208, 9474, 54748, 92727, 93084

#

#####################################################################

# Script Starts Here #

#####################################################################

echo -n "Enter the Lower Limit : "

read Start

echo -n "Enter the Upper Limit : "

read Ending

echo "Armstrong Numbers between $Start and $Ending are: "

while [ $Start -le $Ending ]

do

Number=$Start

Length=${#Number}

Sum=0

OldNumber=$Number

while [ $Number -ne 0 ]

do

Rem=$((Number%10))

Number=$((Number/10))

Power=$(echo "$Rem ^ $Length" | bc )

Sum=$((Sum+Power))

done

if [ $Sum -eq $OldNumber ]

then

echo -n "$OldNumber "

fi

let Start++

done

echo

**OUTPUT:**

# sh armstrong_bw_range.sh

Enter the Lower Limit : 1

Enter the Upper Limit : 500

Armstrong Numbers between 1 and 500 are:

1 2 3 4 5 6 7 8 9 153 370 371 407

# sh armstrong_bw_range.sh

Enter the Lower Limit : 1000

Enter the Upper Limit : 10000

Armstrong Numbers between 1000 and 10000 are:

1634 8208 9474

## Monday, December 20, 2010

Posted by venu k

12 comments | 12:08 PM

Subscribe to:
Post Comments (Atom)

thanks

ReplyDeletegud page!

ReplyDeleten itz xtremely useful for beginners like me..!

Armstrong numbers are---->

ReplyDelete1 2 3 4 5 6 7 8 9 153 370 371 407 1634 8208 9474 54748 92727 93084 548834 1741725 4210818 9800817 9926315 24678050 24678051 88593477 146511208 472335975 534494836 912985153 etc.

1 to 9 armstrong numbers.........????

ReplyDeleteHow.....???????/

This comment has been removed by the author.

DeleteA number N is an Armstrong number of order n (n being the number of digits)

Deleteif

abcd. . . = a^n + b^n + c^n + d^n .+ ...= N

so in case of 1 to 9 number of digit is 1 so 1^1 = 1 ..... but 10 has two digit => 1^2 + 0^2 != 10 ,,,,,

I was growing up. At first, kids don't venture far from the home base tree. When they get older, faster, more confident of their surroundings, they venture further. nikon coolshot 20

ReplyDeleteBrilliant stuff! This was hilarious and so well written. I really loved it :)

ReplyDeletec++ beginners lab assignments is c++ code archive

ReplyDeleteĐơn vị vận chuyển gửi hàng từ việt nam sang Hoa Kỳ

ReplyDeleteCông ty vận chuyển gửi hàng từ việt nam sang Lôn-đôn chi phí rẻ

Đơn vị ship nhanh hàng hóa từ việt nam sang thái lan chi phí thấp

ty

ReplyDeleteThe information you share is very useful to me, thank you so much for the article

ReplyDelete