Write a Shell Bash Script for check if a provided number is Armstrong or not
Latest posts by Rajesh Kumar (see all)
- Medical Laboratory equipment manufacturing company - December 20, 2024
- Discover the Heart of India with Mera Apna Bihar - December 20, 2024
- Experience the Pulse of Bangalore with Bangalore Orbit - December 20, 2024
#Your’s is wrong and works only for 3 digits but this one works flawlessly
#!/bin/bash
read -p “Enter Number:” num
temp=$num
arm=0
count=${#num}
if [ $num -lt 10 ]
then
echo “$num is armstrong number (1-9)”
else
while [ $num -gt 0 ]
do
rem=$((num%10))
arm=$((arm + rem**count))
num=$((num/10))
done
if [ $arm -eq $temp ]
then
echo “$arm = $temp Armstrong Number!”
else
echo “$arm != $temp Not a Armstrong Number!”
fi
fi