Write a Shell Bash Script for check if a provided number is Armstrong or not
Latest posts by Rajesh Kumar (see all)
- Best AI tools for Software Engineers - November 4, 2024
- Installing Jupyter: Get up and running on your computer - November 2, 2024
- An Introduction of SymOps by SymOps.com - October 30, 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