Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Shell Bash Scripting: Assignment & Excercise – 11


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


Rajesh Kumar
Follow me
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
s9py
s9py
1 year 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

1
0
Would love your thoughts, please comment.x
()
x