Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

shell script to enter a number and check the number is perfect number or not

# !/bin/bash
echo "Enter a number"
read no  
i=1
ans=0
for i in 1 2 3 4 5 .. no  
do
        if [[ $((no%i)) -eq 0  ]]  
        then
            ans=$((ans + i))
            
fi
i=`expr $i + 1`
done

if [ $no -eq $ans ]  
then
        echo "$no is perfect"
        else
        echo "$no is NOT perfect"
fi
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #shell #script #enter #number #check #number #perfect #number
ADD COMMENT
Topic
Name
1+9 =