Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

Shell Bash Scripting: Assignment & Excercise – 11


Write a Shell Bash Script for check if a provided number is Armstrong or not


Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals

Similar Posts

Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
s9py
s9py
2 years ago

#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