Write a Shell Bash Script for check if a provided number is Armstrong or not
Latest posts by Rajesh Kumar (see all)
- How to remove sensitive warning from ms office powerpoint - July 14, 2024
- AIOps and DevOps: A Powerful Duo for Modern IT Operations - July 14, 2024
- Leveraging DevOps and AI Together: Benefits and Synergies - July 14, 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