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

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...
***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...
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...
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.
C# Create a console application named that creates a list of shapes, uses serialization to save...
C# Create a console application named that creates a list of shapes, uses serialization to save it to the filesystem using XML, and then deserializes it back: // create a list of Shapes to serialize var listOfShapes = new List<Shape> { new Circle { Colour = "Red", Radius = 2.5 }, new Rectangle { Colour = "Blue", Height = 20.0, Width = 10.0 }, new Circle { Colour = "Green", Radius = 8 }, new Circle { Colour = "Purple",...
:  Create a new blank C# console application Your basal metabolic rate is the rate...
:  Create a new blank C# console application Your basal metabolic rate is the rate at which the body uses energy while at rest to keep vital functions going, such as breathing and keeping warm. This calculation is vital to weight management, as it allows you to determine calories needed to maintain, lose, or gain weight. To determine your BMR, use the appropriate formula: Female: 655+(4.35 x weight in pounds)+(4.7 x height in inches)-(4.7 x age in years) Males:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT