Program to Check Prime or Not Prime Number > Unix Shell Programming - counter
Sponsored Links


Popular Links


List of Abbreviations

National Highways in India

States & Union Territories of India

Currency of All Countries

Program to Check Prime or Not Prime Number > Unix Shell Programming

You are Here: Home > Computer Subjects > Unix Shell Programming…

 

Program to Check Prime or Not Prime Number

Code:

clear

echo -n "Enter a Number==> "
read n

i=2
j=`expr $n - 1`
s=1

while test $i -le $j
do
	t=`expr $n % $i`

	if test $t -eq 0
	then
		s=0
	fi

	i=`expr $i + 1`
done

if test $s -eq 1
then
	echo "This is a Prime Number!!!"
else
	echo "This is Not a Prime Number!!!"
fi

Output:

Enter a Number==> 4

This is Not a Prime Number!!!

————————————————————-

Enter a Number==> 11

This is a Prime Number!!!

 

Click Here to Find Latest Jobs and Current Affairs

 

Updated: June 1, 2013 — 4:33 am
© 2016. All Rights Reserved. WikiIND.com