Question

In: Computer Science

Create a C# Windows Console application that displays the following patterns separately, one after the other....

Create a C# Windows Console application that displays the following patterns separately, one after the other. You MUST use nested for loops to generate the patterns. 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:

Pattern A

*
**
***
****
*****
******
*******
********
*********
**********

Pattern B

**********
*********
********
*******
******
*****
****
***
**
*

Pattern C

**********
 *********
  ********
   *******
    ******
     *****
      ****
       ***
        **
         *

Pattern D

         *
        **
       ***
      ****
     *****
    ******
   *******
  ********
 *********
**********

Solutions

Expert Solution

Here is the solution,

// your code starts here
using System;
using System.Globalization;

namespace patterns
{
class Program
{
static void Main(string[] args)
{
// for pattern A
Console.WriteLine("Pattern A");
for (int i=1; i<=10; i++)
{
for(int j=1; j<=i; j++)
{
Console.Write("*");
}
Console.WriteLine();
}

// for pattern B
Console.WriteLine("Pattern B");
for (int i = 10; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
Console.Write("*");
}
Console.WriteLine();
}


// for pattern C
Console.WriteLine("Pattern C");
for (int i = 10; i >= 1; i--)
{
for(int j=i; j <= 9; j++)
{
Console.Write(" ");
}
  
for (int j = 1; j <= i; j++)
{
Console.Write("* ");
}
Console.WriteLine();
}
// for pattern D
Console.WriteLine("Pattern D");
for (int i = 1; i <= 10; i++)
{
for (int j = i; j <= 10; j++)
{
Console.Write(" ");
}

for (int j = 1; j <= i; j++)
{
Console.Write("* ");
}
Console.WriteLine();
}
}
}
}
// code ends here

here is the screenshot of the code:-

Thank You.


Related Solutions

In C# Create a windows application which accepts the month number and displays the month name...
In C# Create a windows application which accepts the month number and displays the month name in a label.   Use a nested if... else statement to determine the month name. For months not in the range 1-12 display the message "Not a valid month"
Write a program that displays the following patters separately, one below the other in a TextBox.
(Triangles of Asterisks)Write a program that displays the following patters separately, one below the other in a TextBox.Use For..Next loops to generate the patterns. All asterisks (*) should be displayed one at a time by the statement outputTextBox.AppendText(“*”) (this causes the asterisks to display side by side).The statement outputTextBox.AppendText(vbCrLf) can be used to position to the next line, and a statement of the form outputTextBox.AppendText(“ “) can be used to display spaces for the last two patterns. There should be...
You've been hired by Yogurt Yummies to write a C++ console application that calculates and displays...
You've been hired by Yogurt Yummies to write a C++ console application that calculates and displays the cost of a customer’s yogurt purchase. Use a validation loop to prompt for and get from the user the number of yogurts purchased in the range 1-9. Then use a validation loop to prompt for and get from the user the coupon discount in the range 0-20%. Calculate the following:         ● Subtotal using a cost of $3.50 per yogurt.         ● Subtotal...
C# Create a console application that prompts the user to enter a regular expression, and then...
C# Create a console application that prompts the user to enter a regular expression, and then prompts the user to enter some input and compare the two for a match until the user presses Esc: The default regular expression checks for at least one digit. Enter a regular expression (or press ENTER to use the default): ^[a- z]+$ Enter some input: apples apples matches ^[a-z]+$? True Press ESC to end or any key to try again. Enter a regular expression...
Language: C# Create a new Console Application. Your Application should ask the user to enter their...
Language: C# Create a new Console Application. Your Application should ask the user to enter their name and their salary. Your application should calculate how much they have to pay in taxes each year and output each amount as well as their net salary (the amount they bring home after taxes are paid!). The only taxes that we will consider for this Application are Federal and FICA. Your Application needs to validate all numeric input that is entered to make...
In C# Create a GUI application that calculates and displays the total travel expenses of a...
In C# Create a GUI application that calculates and displays the total travel expenses of a business person on a trip. Here is the information that the user must provide: Number of days on the trip Amount of airfare, if any Amount of car rental fees, if any Number of miles driven, if a private vehicle was used Amount of parking fees, if any Amount of taxi charges, if any Conference or seminar registration fees, if any Lodging charges, per...
C# & ASP.NET Create a console application that prompts the user to enter a regular expression,...
C# & ASP.NET Create a console application that prompts the user to enter a regular expression, and then prompts the user to enter some input and compare the two for a match until the user presses Esc: The default regular expression checks for at least one digit. Enter a regular expression (or press ENTER to use the default): ^[a- z]+$ Enter some input: apples apples matches ^[a-z]+$? True Press ESC to end or any key to try again. Enter a...
***IN C# ONLY, USING WINDOWS FORMS*** --NO JAVA--. Create a GUI application in C# that calculates...
***IN C# ONLY, USING WINDOWS FORMS*** --NO JAVA--. Create a GUI application in C# that calculates and displays the total travel expenses of a business person on a trip. Here is the information that the user must provide: • Number of days on the trip • Amount of airfare, if any • Amount of car rental fees, if any • Number of miles driven, if a private vehicle was used • Amount of parking fees, if any • Amount of...
Must be in Visual C# using windows forms : Create an application that opens a specified...
Must be in Visual C# using windows forms : Create an application that opens a specified text file and then displays a list of all the unique words found in the file. Hint: Use a LINQ method to remove all duplicate words.
Create a Windows application in C# that can be used to change the form color. Your...
Create a Windows application in C# that can be used to change the form color. Your form background color should initially be blue. Provide at least two buttons with two different color choices and a Reset option. Change the font style and size on buttons. Align the buttons so that they are in the center of the form. The color choice buttons should be the same size. Add event handlers for the buttons so that when the user click the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT