08 December 2012

Shell Script to find Armstrong number between 1 to 500

2 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...

2 comments: