![]() |
|
#1
|
|||
|
|||
prime numbersi gotta find the first 100 prime numbers including their reverse or emirps. im tryin to figure out how to come up with something that would test if a number is prime or not. there's no input, only output, so i'm gonna need a loop that keeps going till 100 are found.
since a prime is something that's only divisible by 1 and itself, what i thought was that i would define it as num%(any number from 2 to 9) != 0. i used a bunch of &&s to account for each, and wrote them all out. since a mod remainder of 0 would mean a clean division with nothing left over. is there a more effective way to find out primes? the backwards thing i think i got figured out by using a loop, and then i'll test those with the same criteria as the primes. |
|
#2
|
||||
|
||||
Re: prime numbersSince primes (ex 2) are all odd, use a loop that starts at 3 and skips by 2.
Inside this loop would be another loop that runs from 3 to 1/2 of the number being tested (a rough ending for the max possible). Also, search this site for prime... __________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#3
|
|||
|
|||
Re: prime numbershmmm... i see. so to find a prime you divide the number by half of the number and see if there's a remainder? i heard about using square roots too
but if they're odd then half of the number won't be an integer, which means it won't divide out without a remainder. well that's the point of a prime isn't it? gettin kinda confused anyway here's some of the code in the main function i got just for starters. i know it's not correct since it doesn't account for alot, like the first few primes, and i have to actually keep writing out numbers that it could possibly be divided by. i looked through a few other pages, but which is the most ideal for finding them? CPP / C++ / C Code:
|
|
#4
|
|||
|
|||
Re: prime numbersactually scratch that last code for now. ill just temporarily use some that i found by digging through these threads and applying it to my problem
CPP / C++ / C Code:
on first glance it seems to work, but when you look, it doesn't have all of the right numbers and for some reason 32 and 1024 are in there... i don't get how.. doesn't make sense |
|
#5
|
||||
|
||||
Re: prime numbersQuote:
Example: 63: 63/3 - remainder 63/5 - remainder 63/7 - no remainder -- not prime 29: 29/1 - remainder 29/3 - remainder 29/5 - remainder 29/7 - remainder 29/9 - remainder 29/11 - remainder 29/13 - remainder -- prime... __________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#6
|
|||
|
|||
Re: prime numbersyeah thanks for clarifying that. i got it to work now
|
Recent GIDBlog
Writing a book by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Table | killer9012 | C++ Forum | 29 | 10-Oct-2006 22:15 |
| Python script: Prime numbers | crystalattice | Python Forum | 4 | 16-Apr-2006 09:19 |
| Linear Search | eccoflame | C Programming Language | 3 | 19-Apr-2005 09:36 |
| prime numbers | quasimof | C++ Forum | 1 | 01-Nov-2004 20:35 |
| Help w/ prime # determination | crystalattice | C Programming Language | 17 | 18-Apr-2004 22:43 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The