Homework 7: Parallelogram Program
Objective: To output a parallelogram of the specified size and makeup.
Write a program that behaves as shown below:
This program will output a parallelogram.
How long do you want each side to be? 6
Please enter the character you want it to be made of: @
@
@@
@ @
@ @
@ @
@ @
@ @
@ @
@ @
@@
@
This program will output a parallelogram.
How long do you want each side to be? 9
Please enter the character you want it to be made of: *
*
**
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
**
*
Here are the rules and hints:
- Your program must output the parallelogram just one character at a time, inside a loop.
- Your program must work with any length greater than 1. (You don't need to do any error checking for
bad input)
- Your program must use the character the user inputs to draw the parallelogram.
- You cannot use an array to store the parallelogram.
- Hint: I recommend you think of this as a program to output two triangles, one above the other (the longest horizontal line is the border between the triangles).
- Hint #2: To make this easier to solve, start by writing a program that outputs this text for the last example above:
1*
2*
3*
4*
(etc.)
After that is done, then figure out how to output the right number of characters.
- Hint #3: In Section 4.8 of your text book (page 175) there is a nested loop example to output a triangle, which may help you
figure out how to draw the top half of your parallelogram.
Return to main CS 111A page