Find Prime Number Bash shell programming Linux and Unix OS

If the number is divided by itself and one then it is called prime no. 7 is the prime no, 4 is not prime number, using basic airthematic operation in bash shell programming in Linux and UNIX OS we can find the give number is prime number or not
Source code bash shell Programming Algorithm
echo "Enter the number"
read a
i=2
z=0
while [ $i -lt $a ]
do
s=`expr $a % $i`
if [ $s -eq $z ]
then
echo "Not Prime"
exit
else
i=`expr $i + 1`
fi
done
echo "Prime number"

OUTPUT Find PRIME NUMBER CS1252 Operating Systems lap
[redhat35@localhost Rhel5]$ sh prime.sh
Enter the number
7
Prime number
[redhat35@localhost Rhel5]$ sh prime.sh
Enter the number
4
Not Prime

Post a Comment

3 Comments

dileep mani said…
This comment has been removed by a blog administrator.
Anonymous said…
Nice code easy to understand
Anonymous said…
This comment has been removed by the author.