08 December 2012

Shell Script to find Armstrong number between 1 to 500

3 comments

Q. How do I write Bash Script to find Armstrong number


Ans:

#!/bin/bash
#Script to find armstrong number till 500, you can change it 
i=1
while((i<=500))
do
c=$i
d=$i
b=0
a=0
#checking each number
while((c>0))
do
#separating each digit
a=$((c%10))
#finding cube of each digit and adding them
b=$((b + a*a*a))
c=$((c/10))
done
if((b==d)); then
echo "$i"
fi
i=$((i+1))
done

Output


shell script to find Armstrong number

Enjoy :)


If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

3 comments:

  1. Hi, thanks for your great information! Well, it really seems so great. http://www.lowhosting.com/networksolutions-review/

    ReplyDelete
  2. Your effort in writing this is really praiseworthy, thank you so much. Read this article for complete details. The CPS Test is one of the most popular online tests.

    ReplyDelete