#include #include #include #include // problem #1 // precondition: num is >= 1 int factorial(int num) { if (num == 1) return 1; else return num * factorial(num - 1); } // problem #2 // precondition: num is >= 1, high starts off at num, and low starts off at 1 int squarert(int num, int high, int low) { int midpt; if (high==low) return high; // if there is no exact match, return what's close midpt = (high+low)/2; if (midpt * midpt == num) return midpt; // perfect match else if (midpt * midpt > num) // guess is too high return squarert(num, midpt-1, low); // we know our guess is beyond what the highest # could be else return squarert(num, high, midpt+1); // else our guess is too low } // problem #3 // precondition: counter starts at vector.length() - 1 int sumapvector(const apvector &vector, int counter) { if (counter < 0) return 0; // indexes below 0 aren't possible, so the answer should be nothing return vector[counter] + sumapvector(vector, counter - 1); }