![]() |
|
#1
|
|||
|
|||
prime numbersi wrote this program to find prime numbers, but whenever i run it, i get an error.
This is the code [c++]: CPP / C++ / C Code:
My real task is to get the user to input a number greater than 2, and then print out what prime numbers added together would make up the number the user inputed. For example: 4 = 2 + 2 6 = 3 + 3 8 = 3 + 5 10 = 3 + 7 etc. i need to create a function: void Goldbach(int n, int& p1, int & p2) and the main program would be: CPP / C++ / C Code:
Last edited by dsmith : 01-Nov-2004 at 15:44.
Reason: Please use [c] & [/c] for syntax highlighting
|
|
#2
|
||||
|
||||
|
Hi quasimof. Your program is giving you an error, because the first time through your loop i is 0. You are dividing num by i and any number divided by 0 is... undefined.
Anyway, I don't think your logic is sound either. If you search these forums you should be able to find several threads that have good prime number finding algorithms such as this one here. Once you get your prime number tester working, your other function should fall right into place ![]() Good luck! __________________
The best damn Sports Blog period. |
Recent GIDBlog
First week of IA training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help with random numbers | da_bomb50 | MySQL / PHP Forum | 3 | 04-Aug-2004 19:34 |
| Factorial of numbers | cior | CPP / C++ Forum | 7 | 09-Jun-2004 20:08 |
| [CONTEST?]Data Structure Test | dsmith | C Programming Language | 2 | 06-Jun-2004 15:13 |
| Help w/ prime # determination | crystalattice | C Programming Language | 17 | 18-Apr-2004 21:43 |
| Best way to validate numbers (ids)? | JdS | MySQL / PHP Forum | 1 | 20-Jan-2003 03:55 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The