#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
int i,n;
clrscr();
cout<<"Enter an integer number\t";
cin>>n;
for(i=2;i<=n/2;i++)
if(n%i==0)
{
cout<<n<<"is not a prime number";
getch();
exit(0);
}
cout<<n<<" is a prime number\t";
getch();return;

}

HEY DUDE HERE IS A SIMPLE PROGRAM TO FIND PRIME NUMBERS

Nick Evan commented: if (postcount > 10 && !codetags) rep--; -2

oohh..Am extremely sorry.. Of course I was not shouting.. :) I am new to this community..that is why i was unaware of the rules.. will obey them from now onwards ...

An I have a doubt.. i thought getch() is the standard c++ thingy.. and getchar is the C one.. !

thanks for informing...

bye

An I have a doubt.. i thought getch() is the standard c++ thingy.. and getchar is the C one.. !

Not really. getchar() is the standard C, and cin.get(); (from the std namespace) is the 'standard' C++ one.
Getch() is something Borland Turbo C++ came up with and although it has it's purposes, it is not standard C/C++ so a lot of compilers won't compile your code. (same goes for clrscr() btw)

Hmmmm, I'm not to sure if your teacher is forcing a particular method, but mod is useful for this kind of thing:

int iNum(7);
bool bPrime(false);
//since even primes have a factor of 1
//and themself, start at 2 and stop 1 less than the number
for (int i = 2; i < iNum - 1; ++i)
{
//if there is no remainder, its not prime!
if (!(i % iNum))
{
bPrime = true;
break;
}
}

That's the simplest method I can think of, although I'm sure there's several more.

Looks like somebody already posted a better version of my code :P . I guess it makes sense to only iterate halfway through iNum...

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.