0% found this document useful (0 votes)
131 views

Unix Shell Program To Print Range of Prime No

This Unix shell program prints prime numbers within a specified range of numbers. The user is prompted to enter a number range. The program then uses a nested while loop to check each number from 1 to the input range for primality. It divides each potential prime by all integers from 1 to itself, counting the number of remainders of 0. If only 2 remainders are found, the number is prime and printed as output.

Uploaded by

chinmoyghorai
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views

Unix Shell Program To Print Range of Prime No

This Unix shell program prints prime numbers within a specified range of numbers. The user is prompted to enter a number range. The program then uses a nested while loop to check each number from 1 to the input range for primality. It divides each potential prime by all integers from 1 to itself, counting the number of remainders of 0. If only 2 remainders are found, the number is prime and printed as output.

Uploaded by

chinmoyghorai
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Unix Shell Program to print range of Prime no's in a Desired

Range.
Program:
echo enter the range
read n
i=1
echo prime no.s are
while test $i -le $n
do
m=$i
b=0
c=0
j=1
while test $j -le $m
do
c=`echo $m % $j | bc`
if test $c -eq 0
then
b=`echo $b + 1 | bc`
fi
j=`echo $j + 1 | bc`
done
if test $b -eq 2
then
echo $m
fi
i=`echo $i + 1 | bc`
done

You might also like