PS 3

  1. A simple primality testing programme works like this.
    1. Check if the number is 2 or 3.
    2. Check it is of the form 6n+/-1, all primes that aren't 2 and 3 are of this form.
    3. Divide it by every odd number not greater than its square root.
    Write a primality testing programme along these lines, it should also give two factors if there are factors. Do this in a way that has at least two functions, the first should return a bool telling you if the number is of the form 6n+/-1, the second should return a bool telling you if the number is divisible by another number m and should use pass-by-reference to return the value of the result of that division.
  2. Write a programme which uses a recursive function to print a word backwards, in other words, if the string passed to it is empty it should return, if it has letters in it, it should print the last one and call itself on the string with the last letter removed. The string methods you need are .length() which gives the length, .at(int i) which returns the ith char and .erase(int i,int n) which erases n chars starting with the ith one. Remember that the numbering starts at 0.