:sad: My teacher is killing me, he just graduated from Yale, and he hasn't been teaching long that is very apparent. I don't know, but I think this has something to do with the complexity of his assignments for this, the first class you take for Computer Science, C++.
In our first assignment on functions, he gives us this. He wants us to find any two prime numbers that add up to an even number. He wants us to print out every even number from 4 to 1000, and the two prime numbers which add up to it. for example: 4=2+2 , 10=3+7 , 12=5+7 36=13+23
We have to implement these 4 functions:
int checkPrimer(int n)
Checks if n is a prime number. Return 1 if yes, return 0 if not.
{ for(int m = 2; m*m <= n; m++)
if(n % m == 0)
return 0;
return 1;
}
int findNextPrimer(int n)
Finds next prime number > than n.
findNextPrimer(20)=23
This function must call checkPrimer.
input n
m = n + 1;
Call checkPrimer(m)
if it is prime return m.
if it is not prime m = m +1,
then call checkPrimer(m) again
int onePlusOne(int e)
Given even number e, find where e=p1+p2.
It returns p1(we can compute p2, because p2=e - p1)
This function must call checkPrimer & findNextPrimer.
input e which is > 4
assign 3 to p1
p2 = e - p1
Call checkPrimer(p2)
if yes return p1
if no then p1 = findNextPrimer(p1)
is p1 <= e, if yes go back up to the
p2 = e - p1 step
int printVerification(int e1, int e2, int width)
Prints out all e=p1+p2, for all even numbers e
between e1 & e2. Width is used to control amount
of expressions on each row. This function must call onePlusOne.
I must use printVerification to output (4, 1000, 5).
Each expression takes 30 spaces, each row has 5 expressions.
Print all twin primer pairs between 4 & 1000. (11, 13) is one pair, they equal 24 and equal number.
Any pointers would be welcome, thankyou in advance. :confused: