Write Unix Shell Script Print Armstrong Numbers 1 1000 Program Include Following Key Point Q37088709

Write a Unix Shell Script to print all Armstrong Numbers between1 and 1000.

Your Program should include following key points:

  1. Program should have Header Comments.
  2. Program should print all Armstrong numbers between 1 and1000:

1

153

370

371

407


Solution


If you have any doutbs, please give mecomment…

i=1

n=1000

while [ $i -le $n ]

do

j=$i

sum=0

while [ $j -gt 0 ]

do

rem=`expr $j % 10`

sum=`expr $sum + $rem * $rem * $rem`

j=`expr $j / 10`

done

if [ $sum -eq $i ]

then

echo $i

fi

i=`expr $i + 1`

done

nagaraju@nagaraju-Vostro-3550:~/Desktop/CHEGG/2019/April/180420195 sh /armstrong.sh 153 370 371 407

nagaraju@nagaraju-Vostro-3550:~/Desktop/CHEGG/2019/April/180420195 sh /armstrong.sh 153 370 371 407

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.