Namespace Class Static Void String Int Int New Int Int: Program

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

namespace ConsoleApplication21

{
class Program
{
static void Main(string[] args)
{
int i, v, n, f, x, y, z;

int[,] espiral = new int[100, 100];


Console.Write("digite el valor de n:");
n = int.Parse(Console.ReadLine());

z = i = 1;
f = n;
v = n * n;
while (z < v)
{
for (x = i; x <= f - 1; x++)
{
espiral[x, f] = z;
z++;
}

for (x = f; x >= i + 1; x--)


{
espiral[f, x] = z;
z++;
}

for (x = f; x >= i + 1; x--)


{
espiral[x, i] = z;
z++;
}

for (x = i; x <= f - 1; x++)


{
espiral[i, x] = z;
z++;
}

f--;
i++;

Console.WriteLine("--------------------------");

for (x = 1; x <= n; x++)

{
Console.Write("|");
for (y = 1; y <= n; y++)
{
Console.Write("\t {0}", espiral[x, y]);
}
Console.WriteLine("\t|");
}

Console.ReadKey();

}
}
}

You might also like