Enter the row: 5
1
2 3 4
5 4 3 2 1
2 3 4 5 4 3 2
1 2 3 4 5 4 3 2 1
1
2 3 4
5 4 3 2 1
2 3 4 5 4 3 2
1 2 3 4 5 4 3 2 1
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the row
number");
int n = int.Parse(Console.ReadLine());
bool flag = true;
int temp = 1;
for (int row = 0; row <= n; row++)
{
for (int space = n; space > row; space--)
{
Console.Write(" ");
}
for (int coll = 0; coll < row * 2 - 1; coll++)
{
Console.Write(temp);
if (temp != n &&
flag)
{
temp++;
if (temp == n)
{
flag = false;
}
}
else
{
temp--;
if (temp == 1)
{
flag = true;
}
}
}
Console.WriteLine();
}
Console.WriteLine();
Console.ReadLine();
}
}
No comments:
Post a Comment