Code In Tech - The Ultimate World of Computer Technology

Saturday, 12 May 2012

Shell script to print the series of a prime no. up to given no.

SOURCE CODE:


echo  “Enter the no:“
read n
i=1
echo $i
while [ $i -le $n ]
do
     k=2
     while [ $k – lt $i ]
     do
           j =`expr $i % $k`
           if [ $j = 0 ]
           then
                break;
           fi
k =`expr $k + 1`
done
if [ $k = $i ]
then
           echo $i
fi
i =`expr $i + 1`
done

OUTPUT

Enter the no:
6
1
2
3
5
 

No comments :

Post a Comment