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