| 
CMSC201 Programming Project Two
 
Goldbach's Conjecture 
Out: Tuesday 3/4/97Due: Midnight Tuesday 3/18/97
 | 
 The Objective 
The objective of this assignment is to give you some practice using for 
loops, using #define for constants, writing functions and formatting output.
 The Background 
Christian Goldbach did important work in number theory, much of it in 
correspondence with Euler.  He is best remembered for his conjecture, made 
in 1742 in a letter to Euler and still an open question, that every even 
integer greater than 2 can be represented as the sum of two primes.
Some biographical information on Goldbach:  
Born: March 18, 1690 in Konigsberg, Prussia (now Kaliningrad, Russia)
Died: November 20, 1764 in Moscow, Russia
In 1725 Goldbach became professor of mathematics and historian at St. 
Petersburg.  Then, in 1728, he went to Moscow as tutor to Tsar Peter II.
 The Task 
You are to test out Goldbach's conjecture on the even numbers between 200
and 400.  The values 200 and 400 are the constants START and FINISH, 
respectively.  Your program should display the value and the two primes
that when added produce that value as their sum. (See the sample run below)
Your output should match the sample run shown below, exactly.  There should
be 3 values and their primes displayed on each line of output. 
You will be expected to use three functions, other than main, when writing 
your program.  Here are the function prototypes:
void PrintExplanation (void);
int  Goldbach (int n);
bool IsPrime  (int n);
Function Descriptions:
- PrintExplanation - should print a message to the user, explaining
what the program will do.  Since this function returns nothing, it can also 
be called a procedure.
 
- Goldbach - This function will take a positive even integer as its 
single argument, n.  One at a time, the function will test odd integers 
between 3 and n to see if that odd integer is a prime number. (1 is not 
prime, by definition) When a prime number is found, it should be subtracted
from n.  The result needs to be tested to make sure that it is also a
prime number.  If the result is also prime, you've found the two primes that
sum to the even number being checked.  The function needs to return the first
of these two primes.  Functions can only return one thing, in this case, one
integer.  That integer happens to be the first prime number found that when 
subtracted from the even number, n, results in a prime number. 
 
- IsPrime - This function is a predicate function.  It returns TRUE if the
number passed to it is a prime number and FALSE otherwise.  A prime number
is a natural number (a positive integer) that is evenly divisible only by 
itself and 1.  By definition, 1 is not prime.  So any integer less than or 
equal to 1 is not prime.  Also even positive integers, with the exception of 2,
are not prime.
 The Sample Run 
umbc9[1]% a.out
This program will demonstrate the truth of Goldbach's 
conjecture for the even integers 200 through 400, inclusive.  
The conjecture is that any even integer greater than 2 can
be expressed as the sum of two prime numbers.
200 =   3 + 197     202 =   3 + 199     204 =   5 + 199
206 =   7 + 199     208 =  11 + 197     210 =  11 + 199
212 =  13 + 199     214 =   3 + 211     216 =   5 + 211
218 =   7 + 211     220 =  23 + 197     222 =  11 + 211
224 =  13 + 211     226 =   3 + 223     228 =   5 + 223
230 =   3 + 227     232 =   3 + 229     234 =   5 + 229
236 =   3 + 233     238 =   5 + 233     240 =   7 + 233
242 =   3 + 239     244 =   3 + 241     246 =   5 + 241
248 =   7 + 241     250 =  11 + 239     252 =  11 + 241
254 =   3 + 251     256 =   5 + 251     258 =   7 + 251
260 =   3 + 257     262 =   5 + 257     264 =   7 + 257
266 =   3 + 263     268 =   5 + 263     270 =   7 + 263
272 =   3 + 269     274 =   3 + 271     276 =   5 + 271
278 =   7 + 271     280 =   3 + 277     282 =   5 + 277
284 =   3 + 281     286 =   3 + 283     288 =   5 + 283
290 =   7 + 283     292 =  11 + 281     294 =  11 + 283
296 =   3 + 293     298 =   5 + 293     300 =   7 + 293
302 =  19 + 283     304 =  11 + 293     306 =  13 + 293
308 =  31 + 277     310 =   3 + 307     312 =   5 + 307
314 =   3 + 311     316 =   3 + 313     318 =   5 + 313
320 =   3 + 317     322 =   5 + 317     324 =   7 + 317
326 =  13 + 313     328 =  11 + 317     330 =  13 + 317
332 =  19 + 313     334 =   3 + 331     336 =   5 + 331
338 =   7 + 331     340 =   3 + 337     342 =   5 + 337
344 =   7 + 337     346 =  29 + 317     348 =  11 + 337
350 =   3 + 347     352 =   3 + 349     354 =   5 + 349
356 =   3 + 353     358 =   5 + 353     360 =   7 + 353
362 =   3 + 359     364 =   5 + 359     366 =   7 + 359
368 =  19 + 349     370 =   3 + 367     372 =   5 + 367
374 =   7 + 367     376 =   3 + 373     378 =   5 + 373
380 =   7 + 373     382 =   3 + 379     384 =   5 + 379
386 =   3 + 383     388 =   5 + 383     390 =   7 + 383
392 =   3 + 389     394 =   5 + 389     396 =   7 + 389
398 =  19 + 379     400 =   3 + 397
umbc9[2]% 
  
 Submitting the Program 
To submit the file you should use the command:
submit cs201 proj2 proj2.c
You can check your submission by using the command:
submitls cs201 proj2