Cybercrux

Everything is achievable through technology

C# pattern printing

Pattern
Pattern
class Program
{
static void Main(string[] args)
{
int num = 7;

string[] st = new string[num];

for (int i = 1, f = num; i <= num; i++, f–)
{

if (i < num)
{
st[i – 1] =
new string(‘ ‘, i – 1) +
((i == num) ? ” ” : i.ToString()) +
new string(‘ ‘, f – 2) + i +
new string(‘ ‘, f – 2) + ((i == num) ? ” ” : i.ToString());
}
else if (i == num)
{
for (int k = 1; k <= num; k++) { st[i – 1] += k.ToString(); }
for (int k = num-1; k >= 1; k–) { st[i – 1] += k.ToString(); }
}
}
for (int a = 0; a < num-1; a++) { Console.WriteLine(st[a]); }
for (int aa = num-1; aa >= 0; aa–) { Console.WriteLine(st[aa]); }

Console.ReadKey();
}

}

One thought on “C# pattern printing

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s