C# program to print below number pattern by entering no of lines
1
12
123
1234
12345
1234
123
12
1
Here's a C# program that will print the number pattern you described based on the number of lines entered by the user:
using System;
class Program
{
static void Main()
{
Console.Write("Enter the number of lines: ");
int numOfLines = int.Parse(Console.ReadLine());
PrintNumberPattern(numOfLines);
}
static void PrintNumberPattern(int numOfLines)
{
// Print upper half of the pattern
for (int i = 1; i <= numOfLines; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write(j);
}
Console.WriteLine();
}
// Print lower half of the pattern
for (int i = numOfLines - 1; i >= 1; i--)
{
for (int j = 1; j <= i; j++)
{
Console.Write(j);
}
Console.WriteLine();
}
}
}
Below is the output of the above program:
In this program, the PrintNumberPattern method takes the number of lines as a parameter and uses nested loops to print the numbers in the desired pattern. The first loop is responsible for printing the upper half of the pattern, incrementing the number on each line. The second loop prints the lower half of the pattern, decrementing the number on each line.
When you run the program, it will ask you to enter the number of lines, and then it will print the number pattern accordingly.