30 December 2011

A program in UNIX to check if a number a is prime or not

$ cat>prime.sh
echo enter value of n
read n
flag = 0
k = 2
f = ‘expr $n\ /2’
while [ $k –ne $f ]
do
m = ‘expr $n \% $k’
If [ $n –eq 0]
then
flag = 1
echo the number is not prime
break ;
fi
k = ‘expr $k +1’
done
If [ $flag –eq 0]
then
echo the number is prime
fi

0 comments:

Post a Comment