Spherical objects, such as cannonballs, can be stacked to form a pyramid with one cannonball at the top, sitting on top of a square composed of four cannonballs, sitting on top of a square composed of nine cannonballs, and so forth. Given the following recursive function signature, write a recursive function that it takes as its argument the height of a pyramid of cannonballs and returns the number of cannonballs it contains.
A cannonball pyramid of zero height has no cannonballs.
Level i
has i^2
cannonballs.
Simply add up the number of balls at each level, using recursion.