# Thread: Prime Prime Prime Help Help Help

1. ## Prime Prime Prime Help Help Help

hi everyone, i have being working on this code for a long time.. but couldnt make it right

it is simple find the prime number from the user inputs

this is the code ....

Code:
```bool IsPrime(int iNum)
{
// Check if i is less than square root of iNum (and cast iNum to type double)
for (int i=2; i<=sqrt((double)iNum); i++)
{
if (iNum == ((int)iNum/i)*i)// (inum%i == 0)
return false;
}
return true;
}```
but this is not the exact code that i want ...

my aim is to find the prime number that the user will input the max number,,,

example here:

input: 4
output will be: not prime..

2. Code:
`std::cout << (IsPrime(Input) ? "prime" : "not prime") << std::endl;`

3. try this instead of that code you got there.

Code:
```inline bool IsPrime(long& n)
{
return((n & (n - 1)) == 0);
}```

4. Wow - first thread bumping, and then posting something which plainly isn't an anwer.
Feel proud!.

5. im just pointing out something that is better. and it was not thread bumping... and i dont like you being rude to me...
im trieing to help him out by telling him something thats faster and easier and you bash me.
congrats.

6. >>> and it was not thread bumping...

5. Don't bump threads. (Bumping: posting messages on threads to move them up the list or to post on a thread that has been inactive for two weeks or longer).

7. how is posting something older than 2 weeks bumping a thread? where is the common sense in that. if you just reply to get it up k, or if the question was already answered and there is nothing to discuss ok. but clearly im forced to leave forums again bye..

8. The common sense is that a questioner asking a question here 18 months ago is not likely to be sitting waiting for an answer still. He will have found an answer somewhere else or solved it himself.

If you posted a very basic question 18 months ago, would you still be looking for an answer?

9. you seriously have no common sense. wow. cant you think off that some poeple might still be looking at that thread? someone even redicted to that thread. someone might have find it usefull what i posted. do you really think the forums are gonna get any better by that fked up rule . i dont think so. im gonna enjoy my time at codeguru alot more than here.

10. Originally Posted by Mitsukai
you seriously have no common sense. wow. cant you think off that some poeple might still be looking at that thread?
Those are the rules...

11. >try this instead of that code you got there.
Apparently you didn't.

12. im gonna enjoy my time at codeguru alot more than here.
I think we're going to enjoy your time there a lot more than here, too.

13. Yes, answering the old not answered(but good) questions is a good idea.

14. There are reasons for the rules here. They have been developed over many years, by a lot of very experienced people, and for the most, they work. We will not be changing them anytime soon.

>>> im gonna enjoy my time at codeguru alot more than here.

If you approach codeguru, (where many of us are also regulars of course), the way you approached here, I somehow doubt it.

Feel free to ignore this advice, but the net is a big bad ugly place, where people are quick to flame, and far more mercilessly then you have ever been shown here.

If you have been upset by the way you were treated here, you really need to consider an alternative strategy for your learning process.

Good luck.

15. 1) your repeatedly checking the sqrt of iNum, do it once, before the loop, your wasting precious processing power.
2) your checking all numbers, even and odd, all prime numbers (except 2) are prime, once again wasting precious processes.