C# program to print below number triangle by entering no of lines
1
12
123
1234
12345
Here's a C# program that prints the number triangle 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 numLines = Convert.ToInt32(Console.ReadLine());
PrintNumberTriangle(numLines);
}
static void PrintNumberTriangle(int numLines)
{
for (int i = 1; i <= numLines; 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 user is prompted to enter the number of lines. The 'PrintNumberTriangle' method takes the number of lines as an argument and prints the number triangle accordingly. The inner loop is responsible for printing the numbers from 1 to the current line number. Each line consists of the numbers from 1 to the line number, forming a triangle shape.