// computes and returns the square root of f double rootOf(float f);
Sample solution double |
Sample solution float |
Sample solution answer = rootOf(3.5); |
// beginning of code segment if (a < b) { cout << "a is smaller" << endl; if (b == 10) { cout << "a is less than 10" << endl; } } else { cout << "a may be bigger" << endl; } // end of code segment
Sample solution a may be bigger |
Sample solution a may be bigger - since the a==b would fall under the 'else' case for the top test |
#include <iostream> void q3(int i, int n); int main() { int x; std::cout << "Enter an integer: "; std::cin >> x; q3(5, x); } void q3(int i, int n) { if (n <= 0) { std::cout << "done!" << std::endl; } else { int v = n - i; std::cout << v << std::endl; q3(i, v); } }
Sample solution 15 10 5 0 done! - the initial calls is q3(5,20), then the recursive calls are q3(5,15), q3(5,10), q3(5,5), q3(5,0) |