Sol-Assignment11 - Solution Assignment: Due Date: Print...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Solution Dung Nguyen Assignment: 11 Due Date: November 13, 2009 Print pyramid type figure: Analysis: Input: - Size of the pyramid - Printed character of the pyramid Output: Print a pyramid of given character. The number of rows of printed pyramid is the size of the pyramid. Properties of the pyramid: - If the pyramid has no row, there is nothing. - If the pyramid has n>0 rows, the first (n-1) rows of it form a sub-pyramid. - Each row of pyramid includes the first printed character, blank space or printed character, and a sub-row. Thus we can use recursion to print the pyramid: - Base case : the number of rows equal to 0. - Step case : call the recursive method with number of rows decreased by 1 and then print the corresponding row. Recursion to print a row: - Base case : the current column is the final, i.e. equals to 2*size. - Step case : print the first character and then call the recursive method with the index of column increased by 1 to print the right part of the row. Constrain:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

Sol-Assignment11 - Solution Assignment: Due Date: Print...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online