finding prime numbers that add up to even number?

Reply

Join Date: Apr 2008
Posts: 2
Reputation: LadyPersia is an unknown quantity at this point 
Solved Threads: 0
LadyPersia LadyPersia is offline Offline
Newbie Poster

finding prime numbers that add up to even number?

 
0
  #1
Apr 9th, 2008
Goldbach's conjecture in mathematics is that every even integer number greater than 2 can be expressed as the sum of two prime numbers. Write a program that prompts the user for a number, checks that it is positive and even, and prints the two primes that sum to it.

First I have a question: Is there a mistake? Maybe an even number adds up to 3 primes summed up or even more?

Then... Here's how far I've gotten:
  1. #include <stdio.h>
  2. #include <math.h>
  3. int even (int number);
  4. int prime (int number);
  5. int
  6. main ()
  7. {
  8. int number, sum=0, divisor;
  9. printf ("Please enter a whole number: ");
  10. scanf ("%d", &number);
  11. if (number>=1)
  12. {
  13. prime (number);
  14. }
  15.  
  16. return (0);
  17. }
  18.  
  19. int even (int number)
  20. {
  21. return (!(number%2));
  22. }
  23.  
  24. int prime (int number)
  25. {
  26. if (even (number))
  27. {
I've been stuck here for a while now...
Any hints would be appreciated!
Thank you in advance!
Last edited by Narue; Apr 9th, 2008 at 10:37 am. Reason: Added code tags, do it yourself nex time.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,541
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 704
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: finding prime numbers that add up to even number?

 
0
  #2
Apr 9th, 2008
>I've been stuck here for a while now...
So basically you don't know how to calculate a prime number?
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 2
Reputation: LadyPersia is an unknown quantity at this point 
Solved Threads: 0
LadyPersia LadyPersia is offline Offline
Newbie Poster

Re: finding prime numbers that add up to even number?

 
0
  #3
Apr 9th, 2008
Basically yes... I know how to verify if it's even and positive. But I don't know how to check to see what 2 prime numbers add up to it.
I would need something like say
Entry= 12
then the program needs to say:
11+1=12
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,541
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 704
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: finding prime numbers that add up to even number?

 
0
  #4
Apr 9th, 2008
Start by working out a way of enumerating the prime numbers. If you don't know what the prime numbers below your entered number are, you can't solve the problem. Personally, I would probably create an array of primes to save myself the trouble of calculating them. However, you might want to calculate them, which reduces the current problem from "find two primes that add up to N" to "list all of the primes from 0 to N". That's a much more common problem that you can do research on.

Once you have the primes, it's not terribly difficult to walk over them, take the sum, and compare it with N.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,851
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: finding prime numbers that add up to even number?

 
0
  #5
Apr 9th, 2008
> Maybe an even number adds up to 3 primes summed up or even more?
The sum of 3 odd numbers will always be odd, like the sum of two odd numbers will be even.
What you're suggesting is there are other primes which are even.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1,592
Reputation: jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of 
Solved Threads: 120
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Virtuoso

Re: finding prime numbers that add up to even number?

 
0
  #6
Apr 9th, 2008
First I have a question: Is there a mistake? Maybe an even number adds up to 3 primes summed up or even more?
a mistake where? in Goldbach's Conjecture? if you've found a mistake there, get ready for publication in the journals.

an even number can only be the sum of three primes, if one of those primes is the number 2. which isn't saying anything that the Conjecture isn't already saying. because if you subtract 2 from each side of the equation, you have the original conjecture: "even numbers greater than 2 can be expressed as the sum of two prime numbers"

and i suppose an even number (greater than 6) can be expressed by the sum of four primes because every even number greater than 6 can be expressed as the sum of two even numbers greater than 2.

which brings us back full circle, back to Mr. Goldbach.

the point is that (as far as anyone has ever calculated) ALL even numbers >2 are the sum of two prime numbers.

4 = 2 + 2
6 = 3 + 3
8 = 5 + 3
10 = 5 + 5 or 7 + 3
12 = 5 + 7
14 = 7 + 7 or 11 + 3
16 = 11 + 5 or 13 + 3
18 = 13 + 5 or 11 + 7
20 = 13 + 7
22 = 17 + 5 or 11 + 11
24 = 17 + 7 or 13 + 11
26 = 19 + 7 or 13 + 13
28 = 23 + 5 or 17 + 11
30 = 23 + 7 or 17 + 13
32 = 29 + 3 or 19 + 13
34 = 17 + 17 or 29 + 5 or 31 + 3
36 = 19 + 17 or 29 + 7
38 = 19 + 19 or 31 + 7
40 = 23 + 17 or 29 + 11 or 37 + 3

etc.

I prolly missed a few. but you get the idear.


FYI, here's a tidy list of the first 1000 prime numbers:
http://primes.utm.edu/lists/small/1000.txt




.
Last edited by jephthah; Apr 9th, 2008 at 5:45 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC