List of all available Websheets
Viewing cpp/recursion/textfractal by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | A ruler's pattern makes shorter marks each time you divide the length in half. Mimic this with a method <code>printRuler(n)</code> that prints a ruler like this whose longest line has length <code>n</code>. For example <code>printRuler(2)</code> should print out <pre> - -- - </pre> and <code>printRuler(3)</code> should print out <pre> - -- - --- - -- - </pre> |
Public permissions | |
Engine | |
Template / Reference solution |
using namespace std; void printRuler(int n) { // return if we're in the base case. \[ if (n == 0) return; ]\ // otherwise, make two recursive calls, with a length-n line in between printRuler(\[n-1]\); \[ for (int i=0; i<n; i++) cout << '-'; cout << endl; printRuler(n-1); ]\ } int main() { int n; cin >> n; printRuler(n); } |
C++ test suite json list of stdin/args tests e.g. [{"stdin":"hi", "args":["4", "5"]}, {"stdin":"noargs"}] to just run once with no input use [{}] | [ {"stdin": "1"}, {"stdin": "2"}, {"stdin": "3"}, {"stdin": "4"}, {"stdin": "5"} ] |
Solution visibility |
Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.