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