Thread: Write a program in C to Check Whether a Number can be Express as Sum of Two Prime N0

  1. #1
    Registered User
    Join Date
    Nov 2016
    Posts
    2

    Write a program in C to Check Whether a Number can be Express as Sum of Two Prime N0

    Write a program in C to Check Whether a Number can be Express as Sum of Two Prime Numbers.
    Sample Run :
    Input a positive integer: 16
    Expected Output :
    16 = 3 + 13
    16 = 5 + 11

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    So where is your attempt?

    You can't just roll in, dump your assignment and expect someone to give you an answer on a plate. It doesn't work like that.
    http://cboard.cprogramming.com/c-pro...uncements.html

    At the very least, you should be capable of reading in the required data into suitable variables.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    I'm pretty sure this is a theorem of natural numbers.. not proved yet for all N but certainly not in question.. Then what's the point of this program? Just make the program print 'True'.

    Even if it did the program actually did prove it for the 32 or 64 bit representable integers on a computer, it would not have any tangible benefit. Also I think you might find even proving it for all 16 bit numbers would take a very, very, long time.
    Last edited by MacNilly; 11-28-2016 at 07:41 AM.

  4. #4
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Goldbach's conjecture (every even integer greater than 2 is the sum of two primes) has been shown to be true up to 2 to the 62 (about 4 billion billion). Note that it's only for even numbers (since most primes are odd and you're adding two of them together).

  5. #5
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Wait.. most primes are odd? I thought all primes are odd... cause an even number is divisible by 2, contrary to the definition.. excepting the special cases of 0 and 1, I suppose.

  6. #6
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by MacNilly View Post
    Wait.. most primes are odd? I thought all primes are odd... cause an even number is divisible by 2, contrary to the definition.. excepting the special cases of 0 and 1, I suppose.
    2 is the only even prime number. Divisibility by 2 (itself) does not break the criteria for being prime.

  7. #7
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    Quote Originally Posted by MacNilly View Post
    Wait.. most primes are odd? I thought all primes are odd... cause an even number is divisible by 2, contrary to the definition.. excepting the special cases of 0 and 1, I suppose.
    "Most" is somewhat of an understatement, I guess.

    0 and 1 are not considered prime, so 2 is the lowest prime.

  8. #8
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Then, maybe a better statement, instead of "most primes are odd" is "all primes except 2 are odd".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program to check whether given number is prime or not?
    By avidrutham in forum C Programming
    Replies: 1
    Last Post: 05-26-2015, 04:13 AM
  2. Replies: 3
    Last Post: 12-02-2014, 10:11 AM
  3. Help: How to write a prime number greater than one billion
    By kenryuakuma in forum C++ Programming
    Replies: 6
    Last Post: 12-19-2008, 08:55 AM
  4. Prime number check
    By password in forum C++ Programming
    Replies: 3
    Last Post: 06-25-2007, 10:30 AM
  5. How is to check prime number?
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 10-04-2001, 11:36 PM

Tags for this Thread