Programming Course in C# ¡Free!

DrawParallelogram

 Saturday, April 06, 2013 published by Exercises C#
Proposed exercise

Create a function which draws a parallelogram, with the width, height and character specified as parameters:

DrawParallelogram(10,4,'*');

would display

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

Output



Solution


using System;
class DParallelogram
{
static void DrawParallelogram(int width, int height, char character)
{
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
Console.Write(character);

Console.WriteLine();

for (int c = 0; c <= i; c++)
Console.Write(" ");
}
}