Lab 4: Patterns and Loops

For this lab we will again create a pattern maker program using loops like lab 2.

The lab is broken down into 4 steps.

We have provided the main() function, and you will write the code for each step.

Please complete the lab in pairs.

Step 0: (0 Points)

Take an input from the user for number of lines.

Write a code to  that prints out a right triangle with *.

Running the program should like:

 

  Enter an odd number for max stars: 3

  *

  **

  ***

Step 1: (1 Point)

Write code to accept as input a number (n) at the prompt "Enter an odd number for max stars:"

Your should print the character "*" in the shape of sideways triangle.

Running the program should look like:

  Enter an odd number for max stars: 5

  *

  ***

  *****

  ***

  *

Step 2: (1 Point)

Write code to accept as input a number (n) at the prompt "Enter an odd number for max stars:"

Your code  should print the character "*" in the shape of centered triangle.

Running the program should look like:

  Enter an odd number for max stars: 7

    *

   ***

  *****

 *******

Step 3: (1 Point: Extra Credit)

Write code to accept as input a number (n) at the prompt "Enter an odd number for max stars:"

Your code should print the character "*" in the shape of centered diamond.

Running the program should look like:

  Enter an odd number for max stars: 7

    *

   ***

  *****

 *******

  *****

   ***

    *