Enter the input: 5
1 2 3 4 5
16 6
15 7
14 8
13 12 11 10 9
class Program
1 2 3 4 5
16 6
15 7
14 8
13 12 11 10 9
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a number");
int num = int.Parse(Console.ReadLine());
int temp = 4 * num - 4;
int count = 1;
for (int row = 1;
row <= num; row++)
{
for (int col = 1;
col <= num; col++)
{
if (row == 1)
{
Console.Write(count++ +
" ");
}
else if (col == num)
{
Console.Write(count++ +
" ");
}
else if (col == 1)
{
Console.Write(temp-- + " ");
}
else if (row == num)
{
Console.Write(temp-- + " ");
}
else
{
Console.Write(" " + " ");
}
}
Console.WriteLine();
}
Console.ReadLine();
}
}
No comments:
Post a Comment