Question: Write a recursive function hourglass ( base ) that prints an hour glass to the screen using asterisks. The function has a single paramater, base,
Write a recursive function hourglassbase that prints an hour glass to the screen using asterisks. The function has a single paramater, base, an int which indicates how many asterisks will be used at the top and bottom levels of the hour glass. Each successive level of the hourglass should have two fewer asterisks in it The successive levels should be centered. Once the level has or asterisks it should repeat that level, then invert and grow by two asterisks until it reaches the base level. This should work for both even and odd inputs.
Hint: you may find the center method on str useful. Call helpstrcenter to learn more about it
Hint: you may find it useful to use an auxiliary function sometimes called a helper function This is a technique that allows you to offload your recursion to a second function that has additional parameters that enable you to make the problem easier to solve. In this case, imagine if the body of hourglass simply called another function: hourglasshelperbase currentlevel which would allow you to track how many levels youve printed so far. In this case, hourglass offloads the recursion to hourglasshelper which is where youd define your base and recursive cases.
You do not have to deal with inputs less than
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
