1 2 3 4 5 4 3 2 1
1 2 3 4 4 3 2 1
1 2 3 3 2 1
1 2 2 1
1 1
1 2 2 1
1 2 3 3 2 1
1 2 3 4 4 3 2 1
1 2 3 4 5 4 3 2 1
1 2 3 4 4 3 2 1
1 2 3 3 2 1
1 2 2 1
1 1
1 2 2 1
1 2 3 3 2 1
1 2 3 4 4 3 2 1
1 2 3 4 5 4 3 2 1
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the no of lines");
int n = int.Parse(Console.ReadLine());
for (int row = n; row >= 1; row--)
{
for (int col = 1; col <= row; col++)
{
Console.Write(col);
}
for (int space = 1; space <= ((n - row) * 2) - 1; space++)
{
Console.Write(" ");
}
if (row == n)
{
for (int col = n - 1; col >= 1; col--)
{
Console.Write(col);
}
}
else
{
for (int col = row; col >= 1; col--)
{
Console.Write(col);
}
}
Console.WriteLine();
}
for (int row = 1; row <= n; row++)
{
for (int col = 1; col <= row; col++)
{
Console.Write(col);
}
for (int space = 1; space <= (n - row) * 2 - 1; space++)
{
Console.Write(" ");
}
if (row == n)
{
for (int col = n - 1; col >= 1; col--)
{
Console.Write(col);
}
}
else
{
for (int col = row; col >= 1; col--)
{
Console.Write(col);
}
}
Console.WriteLine();
}
Console.ReadLine();
}
}
No comments:
Post a Comment