SHELL PROGRAM
Check whether the number is armstrong or not ? |Shell Program|
#!/bin/bash
echo "Enter the number"
read num
n=$num
sum=0
while [ $num -gt 0 ]
do
rem=$(($num%10))
sum=$(($sum+($rem * $rem * $rem)))
num=$(($num/10))
done
if [ $sum -eq $n ]
then
echo "$n is armstrong"
else
echo "$n is not armstrong"
fi
OUTPUT
Enter the number
153
153 is armstrong
echo "Enter the number"
read num
n=$num
sum=0
while [ $num -gt 0 ]
do
rem=$(($num%10))
sum=$(($sum+($rem * $rem * $rem)))
num=$(($num/10))
done
if [ $sum -eq $n ]
then
echo "$n is armstrong"
else
echo "$n is not armstrong"
fi
OUTPUT
Enter the number
153
153 is armstrong
Post a Comment
0 Comments