#include<iostream>
using namespace std;
int main()
{
int a,d;
cout<<"Enter a integer to check it is prime or not :";
cin>>a;
d=2;
while(a%d!=0)
{
d++;
}
if(a==d)
{
cout<<"\n the given number id prime ";
}
else
cout<<"\n the given number is not a prime number ;"
return 0;
}
pramod_8
0
Newbie Poster
Recommended Answers
Jump to PostNot a good approach. Set up a Sieve of Aristhostenes array (I usually hard code a 10K array) for initial lookup - remembering that a%2 == 0 indicates the number is even, hence not prime. You only have to deal with odd numbers. If the number you are looking at …
All 2 Replies
rubberman
1,355
Nearly a Posting Virtuoso
Featured Poster
rproffitt
commented:
Some folk find it odd to use prior works. I think this makes us even.
+10
AssertNull
1,094
Practically a Posting Shark
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.