// computes and returns pi to the power of p float powerPi(int p);
Sample Solution float |
Sample Solution int |
Sample Solution answer = powerPi(7); |
// beginning of code segment if (a != b) { cout << "a is " << a << endl; if (b < 0) { cout << "b is negative" << endl; } else { cout << "b is not negative" << endl; } } // end of code segment
Sample Solution a is 7 b is not negative |
Sample Solution - doesn't produce any output at all (no else case so no action if a==b) |
#include <iostream> void q3(int i, int n); int main() { int x; std::cout << "Enter an integer: "; std::cin >> x; q3(1, x); } void q3(int i, int n) { if (i > n) { std::cout << "done!" << std::endl; } else { int v = i * 5; std::cout << v << std::endl; q3(i+1, n); } }
Sample Solution 5 10 15 20 done! - the initial call is q3(1,4), then the recursive calls are q3(2,4), q3(3,4), q3(4,4), q3(5,4) |