lab_quacks
Spiteful Stacks and Questionable Queues
|
Namespace to contain the recursion exercise code. More...
Functions | |
int | sumDigits (int n) |
Given a non-negative int n, return the sum of its digits recursively (no loops). More... | |
int | triangle (int rows) |
We have triangle made of blocks. More... | |
Namespace to contain the recursion exercise code.
int RecursionExercises::sumDigits | ( | int | n | ) |
Given a non-negative int n, return the sum of its digits recursively (no loops).
n | The number to sum the digits of |
Example: sumDigits(126) == 9 sumDigits(49) == 13 sumDigits(12) == 3
int RecursionExercises::triangle | ( | int | rows | ) |
We have triangle made of blocks.
The topmost row has 1 block, the next row down has 2 blocks, the next row has 3 blocks, and so on. Compute recursively (no loops or multiplication) the total number of blocks in such a triangle with the given number of rows.
rows | The number of horizontal rows in the triangle. |