0% found this document useful (0 votes)
25 views3 pages

Dynamic Square 11111

This C# code prompts the user to enter a number and then prints out that number of rows to display a square pattern of asterisks. It uses a for loop with an inner if/else statement to handle the different cases for printing asterisks on the edges or spaces in the middle of each row, incrementing a row counter to handle line breaks between rows.

Uploaded by

Fasih Dawood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views3 pages

Dynamic Square 11111

This C# code prompts the user to enter a number and then prints out that number of rows to display a square pattern of asterisks. It uses a for loop with an inner if/else statement to handle the different cases for printing asterisks on the edges or spaces in the middle of each row, incrementing a row counter to handle line breaks between rows.

Uploaded by

Fasih Dawood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace ConsoleApplication1

class Program

static void Main(string[] args)

Console.WriteLine("Enter number to print Square");

int n = int.Parse(Console.ReadLine());

int a = 0;

for (int i = 1; i <= n; i++)

if (a == 0 || a == n - 1)

Console.Write("* ");

if (a > 0 && a < n - 1)

if (i == 1 || i == n)

Console.Write("* ");
}

else

Console.Write(" ");

Console.Write(" ");

if (i == n)

Console.WriteLine();

i = 0;

a++;

if (a == n)

break;

}
}

Console.ReadLine();

You might also like