Docsity

Practice Assignment 8 - Programming Using C | CGS 3460, Assignments of Computer Science

Toggle sidebar
bg1
CGS 3460 - Programming Using C
Fall 2008
Assignment #8
Assigned: Wednesday, Oct 15th, 2008
Due: Wednesday, Oct 22nd, 2008 at 11:59 PM
1. Goldbach’s conjecture states that every even number greater than two is the sum of
two prime numbers. For example, 4= 2 + 2, 6 = 3 + 3, 8 = 3 + 5, etc. Extensive computer
experiments have found no counterexample, but no proof has been found. Write a
program that will confirm this conjecture for all even numbers (greater than two) between
n and m, where n and m are input by the user. Note that the number 1 is not considered a
prime number for this exercise. Save your program in a file called p1.c. Your program
must use a function to determine whether a number is prime or not.
Example 1:
Enter the value of n: 2
Enter the value of m: 12
4 = 2 + 2
6 = 3 + 3
8 = 3 + 5
10 = 3 + 7
12 = 5 + 7
Example 2:
Enter the value of n: 1
Enter the value of m: 17
4 = 2 + 2
6 = 3 + 3
8 = 3 + 5
10 = 3 + 7
12 = 5 + 7
14 = 3 + 11
16 = 3 + 13
Example 3:
Enter the value of n: 200
Enter the value of m: 220
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
pf2

Partial preview of the text

Download Practice Assignment 8 - Programming Using C | CGS 3460 and more Assignments Computer Science in PDF only on Docsity!

CGS 3460 - Programming Using C

Fall 2008

Assignment

Assigned: Wednesday, Oct 15th, 2008

Due: Wednesday, Oct 22nd, 2008 at 11:59 PM

1. Goldbach’s conjecture states that every even number greater than two is the sum of

two prime numbers. For example, 4= 2 + 2, 6 = 3 + 3, 8 = 3 + 5, etc. Extensive computer experiments have found no counterexample, but no proof has been found. Write a program that will confirm this conjecture for all even numbers (greater than two) between n and m, where n and m are input by the user. Note that the number 1 is not considered a prime number for this exercise. Save your program in a file called p1.c. Your program must use a function to determine whether a number is prime or not.

Example 1: Enter the value of n: 2 Enter the value of m: 12 4 = 2 + 2 6 = 3 + 3 8 = 3 + 5 10 = 3 + 7 12 = 5 + 7

Example 2: Enter the value of n: 1 Enter the value of m: 17 4 = 2 + 2 6 = 3 + 3 8 = 3 + 5 10 = 3 + 7 12 = 5 + 7 14 = 3 + 11 16 = 3 + 13

Example 3: Enter the value of n: 200 Enter the value of m: 220 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

Instructions for submitting Assignment 8

  1. First compress your program files into a tar file. For this, change to the directory where you have stored both the files. At the terminal command prompt (putty, Linux console, MAC terminal, etc.) type: tar cvf assign8.tar p1.c

Let’s say you have stored your files in assign8 directory your “rain” machine.

cd assign ls p1.c

tar cvf assign8.tar p1.c ls p1.c assign8.tar ….

  1. If you are working from Windows platform using Putty and WinSCP, you can create a directory assign8 in your home directory on rain machine using putty. Create the directory using this command on putty > cd //to change to the home directory >mkdir assign8 //to create the directory under home directory
  2. Then transfer p1.c to assign8 directory on rain using WinSCP.
  3. Go to step 1 to tar the file using putty.
  4. Use WinSCP to copy assign8.tar from rain machine back to your local computer, say desktop.
  5. Upload the assign8.tar to WebCT.
  6. Please check the discussion page for assignment 2 on WebCT for common questions and their answers.