In: Computer Science
Create and test a Windows Console application that displays the following patterns separately, one after the other. You MUST use nested for loops to generate the patterns, like the example in the PowerPoint slides from this chapter. All asterisks (*) should be displayed by a single statement of the form Console.Write("*"); which causes the asterisks to display side by side. A statement of the form Console.WriteLine(); can be used to move to the next line. A statement of the form Console.Write(" "); can be used to display a space for the last two patterns. There should be no other output statements in the application, other than labeling each pattern. The application's output should look like the following: Remember, use Debug, Start Without Debugging (CTRL-F5) to run your Console application. For Pattern C and Pattern D, you will need TWO loops (one after the other) nested inside your outer loop. The first loop will produce a certain number of spaces. The second loop will produce a certain number of stars. One of these numbers will be the current value of your outer loop's control variable. The other number must be calculated using ALGEBRA. Consider, how many spaces and stars are being output on each row? Always the same amount (here, 10 or MAX_ROWS, if using the same named constant as in the PowerPoint slide code given for Pattern A). So, (# spaces) + (# stars) = MAX_ROWS This equation is easy to solve for the number of spaces needed (assuming your outer loop control variable represents that number of stars per row, as in the PowerPoint slide code given for Pattern A): (# spaces) = MAX_ROWS - (# stars) or (# spaces) = MAX_ROWS - row if you name your variables as in the PowerPoint slide code given for Pattern A. So, you can make your first nested loop start at 1 and count up to (MAX_ROWS - row), outputting a single space on each iteration
Pattern A * ** *** **** ***** ****** ******* ******** ********* ********** Pattern B ********** ********* ******** ******* ****** ***** **** *** ** *
(c)
**********
*********
********
*******
******
*****
****
***
**
*
(d)
*
**
***
****
*****
******
*******
********
*********