Showing posts with label PRIME NOS. Show all posts
Showing posts with label PRIME NOS. Show all posts

Monday, October 28, 2013

PROGRAM TO FIND PRIME NOS IN C++

//PROGRAM TO FIND PRIME NOS IN C++
#include<iostream.h>
void main()
{
int a;
cout<<"Enter a no"<<endl;
cin>>a;

int s=0;
for(int i=1;i<a;i++)
{
if(a%i==0)
{
s=1;
}
else
{
s=0;
}
}
if(s==1)
cout<<"no is prime";
else
cout<<"no is nt prime";
}

PROGRAM TO FIND PRIME NOS IN SHELL SCRIPT

#PROGRAM TO FIND PRIME NOS IN SHELL SCRIPT
echo "Enter a number: "
read num
i=2
f=0
while [ $i -le `expr $num / 2` ]
do
if [ `expr $num % $i` -eq 0 ]
then
f=1
fi
i=`expr $i + 1`
done
if [ $f -eq 1 ]
then
echo "The number is composite"
else
echo "The number is Prime"
fi


#OUTPUT
#Enter a number:
#5
#The number is Prime